Results 1 to 4 of 4

Thread: CmnDialog

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Guys
    With the CmnDialog script as below, when the user selects multiple files, just the filenames are captured ( which is what I need ), but
    when a single file is selected, the full path is captured.
    Can the lines:
    Case 0 'if only one was selected we are done
    lstFTP.AddItem myFiles(0)

    be changed to just capture the fileame?
    Many thanks.

    Private Sub procAccTrans_Click(Index As Integer)
    On Error GoTo cError

    Dim i As Integer
    Dim myFiles() As String
    Dim myPath As String


    With CmnDialog1
    .MaxFileSize = 32000 'this will max out the buffer for the filenames array for large selections. *NEW*
    .CancelError = False 'if cancel is pressed, the code jumps to cError because of the On Error statement above

    .Filter = "*.*"
    .FilterIndex = 2
    .InitDir = "L:\MMPDF\Transfer\"
    .Flags = CD_FLAGS 'this is where we tell it to use multiselect
    .ShowOpen

    myFiles = Split(.FileName, vbNullChar) 'the Filename returned is delimeted by a null character because we selected the cdlOFNLongNames flag

    Select Case UBound(myFiles)
    Case 0 'if only one was selected we are done
    lstFTP.AddItem myFiles(0)

    Case Is > 0 'if more than one, we need to loop through it and append the root directory
    For i = 1 To UBound(myFiles)
    myPath = myFiles(0) & IIf(Right(myFiles(0), 1) <> "\", "\", "") & myFiles(i)
    lstFTP.AddItem myFiles(i)
    Next i
    End Select

    End With
    Exit Sub

    cError:
    Beep
    MsgBox Err.Description '*NEW*
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try

    Code:
          Case 0   'if only one was selected we are done
                Dim strFile As String
                Dim intPos As Integer
                ' Get filename with path
                strFile = myFiles(0)
                ' Get position of last backslash
                intPos = InStrRev(strFile, "\")
                ' Extract part after last backslash, i.e. the filename
                strFile = Mid(strFile, intPos + 1)
                ' Add the filename
                lstFTP.AddItem strFile

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As ever !! perfect !! Thanks again...

  4. #4
    New Lounger
    Join Date
    Dec 2009
    Location
    Quebec city
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I don,t have the examples in VB, but use this in C#

    DirectoryInfo dir = new DirectoryInfo("C:\\");
    FileInfo[] files = dir.GetFiles("*.*",SearchOption.TopDirectoryOnly);
    foreach (FileInfo file in files)
    {

    Console.WriteLine(file.Name);
    }

    Ben

Posting Permissions

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