|
-
Dec 18th, 2002, 02:57 AM
#1
Thread Starter
Member
How to extract a directory name?
How will i extract a directory name? Like for example:
c:\temp\alvin\alvin.txt
I would just like to have c:\temp\alvin\
-
Dec 18th, 2002, 03:21 AM
#2
Lively Member
you could jus try
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
Regards,
danielsan
'Even though the book is finished. There's no need to close and forget.'
-
Dec 18th, 2002, 04:32 AM
#3
Lively Member
I think this code is shorter
Code:
Dim nPos as long
nPos = InstrRev(strPath,"\")
If nPos<>0 then
strPath = Left(strPath,nPos)
EndIF
-
Dec 18th, 2002, 04:36 AM
#4
Lively Member
absolutely right, now just have to execute that number of times to make sure it is the last \ right?
Regards,
danielsan
'Even though the book is finished. There's no need to close and forget.'
-
Dec 18th, 2002, 04:41 AM
#5
Hyperactive Member
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.
After all "Rust Never Sleeps"
-
Dec 18th, 2002, 06:10 AM
#6
Thread Starter
Member
i will try all your suggestions, thanks a lot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|