-
Hi everybody !
Is there one (or more) of you who can tell me how to get the path of a file getting from the commondialog control : FileOpen ?
I try this, it doesn't get the path but the path and the filename. I only want the Path. :rolleyes:
Thanks in advance. :)
Code:
Private Sub PathCommand_Click(Index As Integer)
Dim File As Object, FilePath As String, FileToOpen As Object
Set File = CreateObject("Scripting.FileSystemObject")
CommonDialog.DefaultExt = ".csv"
CommonDialog.ShowOpen
Set FileToOpen = File.GetFile(CommonDialog.FileName)
FilePath = FileToOpen.Path
Debug.Print FilePath
end sub
[Edited by (B2F)Tom on 07-27-2000 at 04:19 AM]
-
Well ....
(B2FTom), let me confess I don't know a direct solution to your problem, i.e. I don't know how to extract only a path from the common dialog control. But again, why bother?
Once you get the path and the filename, just chop off the filename part and you get the path. To locate the filename, you can search the string for '/'.
-
Why not ?
I didn't think of this solution. But to know if it's possible, i let my post active.
However, thanks for your solution, i'll keep it.
-
why not make a little function to do it
function getPath() as string
Dim strfilename As String
Dim tempchar As String
Dim lengthoffile As Integer
Dim i As Integer
Dim path As String
strfilename = CommonDialog.FileName
lengthoffile = Len(strfilename)
For i = lengthoffile To 0 Step -1
tempchar = Mid(strfilename, i, 1)
If tempchar = "\" Then
path = Mid(strfilename, 1, i)
Exit For
End If
Next
getpath = path
End Function
Hope this helps Ian
-
Ianpbaker, i've already made code which does what i wanted (based on honeybee idea).
But i'm courious and i want to know (if somebody know) how to make it with properties or methods, like i tried the first time. Thanks. ;)
I looked your code and i saw it was a little bigger. I give you what i did, which is smaller, if someday you would like to do it :
Code:
FilePath = CommonDialog.FileName
Do While Mid(FilePath, Len(FilePath), 1) <> "\"
FilePath = Left(FilePath, Len(FilePath) - 1)
Loop