+ Reply to Thread
Results 1 to 3 of 3

Return file name only from FileDialog

  1. #1
    PMC1
    Guest

    Return file name only from FileDialog

    Hi,

    I'm looking for a way to return only the File Name from the FileDialog
    object. From what I can see I can only return both the full path and
    file name.

    I'm open to suggestion of alternative methods other than FileDialog
    such as an API but again any API examples I have found only return the
    full path.

    Has anybody any suggestions on how i could do this?

    Thanks

    Paul


  2. #2
    Tom Ogilvy
    Guest

    RE: Return file name only from FileDialog

    Most would strip out the filename from the fullpathName

    sFileName =
    Right(sFullPathName,Len(sFullPathBName)-InstrRev(sFullPathName,"\"))

    demo'd from the immediate window:

    sFullPathName = "C:\MyMainsubFolder\MySecondarySubFolder\Myfile.xls"
    ? sFullPathname
    C:\MyMainsubFolder\MySecondarySubFolder\Myfile.xls
    sFileName =
    Right(sFullPathName,Len(sFullPathName)-InstrRev(sFullPathName,"\"))
    ? sfileName
    Myfile.xls

    --
    Regards,
    Tom Ogilvy


    "PMC1" wrote:

    > Hi,
    >
    > I'm looking for a way to return only the File Name from the FileDialog
    > object. From what I can see I can only return both the full path and
    > file name.
    >
    > I'm open to suggestion of alternative methods other than FileDialog
    > such as an API but again any API examples I have found only return the
    > full path.
    >
    > Has anybody any suggestions on how i could do this?
    >
    > Thanks
    >
    > Paul
    >
    >


  3. #3
    moon
    Guest

    Re: Return file name only from FileDialog


    If you import GetOpenFileName (comdlg32.dll), the string to return should be
    the FileTitle, not the FileName...

    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
    "GetOpenFileNameA" (pFILETOOPEN As FILETOOPEN) As Long

    Private Type FILETOOPEN
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type

    Private Sub GetFileName()
    Dim FTO As FILETOOPEN
    FTO.lStructSize = Len(FTO)
    FTO.hwndOwner = 0
    FTO.hInstance = 0
    FTO.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) +
    "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    FTO.lpstrFile = Space$(254)
    FTO.nMaxFile = 255
    FTO.lpstrFileTitle = Space$(254)
    FTO.nMaxFileTitle = 255
    FTO.lpstrInitialDir = "C:\"
    FTO.lpstrTitle = "Select a File..."
    FTO.flags = 0
    If GetOpenFileName(FTO) Then
    MsgBox "FileName: " + Trim$(FTO.lpstrFileTitle)
    Else
    'Do nothing
    End If
    End Sub



    "PMC1" <[email protected]> schreef in bericht
    news:[email protected]...
    > Hi,
    >
    > I'm looking for a way to return only the File Name from the FileDialog
    > object. From what I can see I can only return both the full path and
    > file name.
    >
    > I'm open to suggestion of alternative methods other than FileDialog
    > such as an API but again any API examples I have found only return the
    > full path.
    >
    > Has anybody any suggestions on how i could do this?
    >
    > Thanks
    >
    > Paul
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1