How will i extract a directory name? Like for example:
c:\temp\alvin\alvin.txt
I would just like to have c:\temp\alvin\
Printable View
How will i extract a directory name? Like for example:
c:\temp\alvin\alvin.txt
I would just like to have c:\temp\alvin\
you could jus tryVB Code:
Curdir
If that doesn't work you'd have to search the string:
VB Code:
dim endpt as integer 'endpt of the pathstring dim startpt as integer 'startpt of the pathstring dim path as string 'the string with the path dim intpath as integer 'length of the string dim strpath as string 'the actual path endpt=len(path) 'length of the string startpt=0 'if this bugs then try starting at 1. have had this error for i = 0 to endpt 'walk through the entire string startpt = InStr(startpt, Path, "\", vbTextCompare) if startpt <> 0 then 'if nothing is found the startpt is 0 else it will 'increment and stop at 0 intPath = startpt 'intpath is the length end if next i strPath = Mid(strPath, 0, intPath) ' grab the path
Now it might not work 100% but i think you can take it from here;)
I think this code is shorter
Code:
Dim nPos as long
nPos = InstrRev(strPath,"\")
If nPos<>0 then
strPath = Left(strPath,nPos)
EndIF
absolutely right, now just have to execute that number of times to make sure it is the last \ right?
You should only have to use InstrRev once as this function searchs from the end of the string. huyhk's code will work fine as it is.
i will try all your suggestions, thanks a lot! :)