 | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file If the file exists, you can do this:
'~~~~~~~~~~~~~
dim mPath as string, mFile as string
dim mSpec as string
mSpec = "G:\MYPICTURES\123456.JPG"
mFile = DIR(mSpec)
mPath = left(mSpec, _
len(mSpec)-len(mfile))
'~~~~~~~~~~~~~
if you do not know if the file exists...
'~~~~~~~~~~~~~
Function GetPath( _
pSpec as string) _
as String
dim mPath as string, i as integer Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
i = len(mSpec)
for i = len(mSpec) to 1 step -1
if mid(pSpec,i,1) = "\") then
GetPath = _
left(pSpec, i)
exit function
end if
next i
End Function
'~~~~~~~~~~~~~
Warm Regards,
Crystal
Microsoft Access MVP 2006
*
Have an awesome day
remote programming and training
strive4peace2006 at yahoo.com
*
SF wrote:
> Hi,
> Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
> I have file eg G:\MYPICTURES\123456.JPG
>
> What is the function to strip the PATH (eg G:\MYPICTURES\) out of the enture
> string?
>
> SF
>
> | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file SF,
Mid([YourField],InStrRev([YourField],"\")+1)
--
Steve Schapel, Microsoft Access MVP
SF wrote: Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
> Hi,
>
> I have file eg G:\MYPICTURES\123456.JPG
>
> What is the function to strip the PATH (eg G:\MYPICTURES\) out of the enture
> string?
>
> SF
>
> | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file "SF" wrote in message
news:euh0073hGHA.1864@TK2MSFTNGP02.phx.gbl
> Hi,
>
> I have file eg G:\MYPICTURES\123456.JPG
>
> What is the function to strip the PATH (eg G:\MYPICTURES\) out of the
> enture string?
If the file exists, you can use this simple function:
'----- start of code -----
Function PathOnly(FullFilePath As String) As String
PathOnly = _
Left(FullFilePath, _
Len(FullFilePath) - Len(Dir(FullFilePath))) Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
End Function
'----- end of code -----
If the file doesn't exist, you need to do a bit more work:
'----- start of code #2 -----
Function PathOnly2(FullFilePath As String) As String
'Use this version if the file may not exist.
Dim I As Long
I = InStrRev(FullFilePath, "\") Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
If I = 0 Then
I = InStrRev(FullFilePath, ":")
End If
If I = 0 Then
PathOnly2 = FullFilePath
Else
PathOnly2 = Left(FullFilePath, I)
End If
End Function
'----- end of code #2 -----
--
Dirk Goldgar, MS Access MVP www.datagnostics.com
(please reply to the newsgroup) | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file thanks, Steve ... forgot about InStrRev ... old habits die hard!
Warm Regards,
Crystal
Microsoft Access MVP 2006 Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
*
Have an awesome day
remote programming and training
strive4peace2006 at yahoo.com
*
Steve Schapel wrote:
> SF,
>
> Mid([YourField],InStrRev([YourField],"\")+1)
> | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file Well, looks like I may have misinterpreted your question. I assumed
that after a "strip", the interest is more on what's left rather than on Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
what's removed ;-). In any case, even with my interpretation, a simple
Dir([YourField]) would have sufficed. Oh well...
--
Steve Schapel, Microsoft Access MVP
Steve Schapel wrote:
> SF,
>
> Mid([YourField],InStrRev([YourField],"\")+1)
> | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file Hi Steve,
you're not the only one  ... now that you mention it, the
question could be interpreted 2 ways... Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777 Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
Warm Regards,
Crystal
Microsoft Access MVP 2006
*
Have an awesome day
remote programming and training
strive4peace2006 at yahoo.com
*
Steve Schapel wrote:
> Well, looks like I may have misinterpreted your question. I assumed
> that after a "strip", the interest is more on what's left rather than on
> what's removed ;-). In any case, even with my interpretation, a simple
> Dir([YourField]) would have sufficed. Oh well...
> | 
28-Jul-2006, 08:16 AM
|  | Guest | | | | | | | | | | Re: STrip path of a file SF wrote in message :
> Hi,
>
> I have file eg G:\MYPICTURES\123456.JPG
>
> What is the function to strip the PATH (eg G:\MYPICTURES\) out of the
> enture string?
>
> SF
For the fun of it, having a bit of flexibility:
Dim strDrive As String
Dim strDir As String
Dim strFile As String
Dim strExt As String
Const cstrFullName As String = _ Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777 Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=10777
"G:\MYPICTURES\123456.JPG"
With WizHook
.Key = 51488399
.SplitPath cstrFullName, strDrive, strDir, strFile, strExt
Debug.Print strDrive, strDir, strFile, strExt
End With
--
Roy-Vidar | 
Support Us! Become a Promoter! | | Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh! | (View-All)
Members who have read this thread : 0
| | There are no names to display. | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Tools | Search | | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is On | | | | » Active Discussions | | | | | | | | | Panjabi Today 13:43 PM 14 Replies, 287 Views | | | | | | | | | | | | | | | | | | | | | » Books You Should Read... | | | |