Results 1 to 5 of 5

Thread: Files and Path... ?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    North of France
    Posts
    49

    Question

    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.

    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]
    Hi-Tech Engineer

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    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 '/'.
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    North of France
    Posts
    49

    Red face 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.

    Hi-Tech Engineer

  4. #4
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    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
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    North of France
    Posts
    49

    Smile

    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

    Hi-Tech Engineer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width