Results 1 to 9 of 9

Thread: [RESOLVED] Process multiple Files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Resolved [RESOLVED] Process multiple Files

    In this code, I have a list of files through a CommonDialog into a Listbox.

    The user can select multiple files. If only one file is selected, works. If two or more are selected, Output only writes the last path/file line in the list. How can I get the Output to write, creating a bat file, with all path/files in the listbox ?

    I tried to loop through the files and process each file in the listbox without running Shell but could never get it to work correctly.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim FSys As New Scripting.FileSystemObject
    3.  
    4.  
    5. Dim entries As Variant
    6. Dim dir_name As String
    7. Dim i As Integer
    8.  
    9.     On Error Resume Next
    10.     CommonDialog1.ShowOpen
    11.     If Err.Number = cdlCancel Then
    12.         Exit Sub
    13.     ElseIf Err.Number <> 0 Then
    14.         MsgBox "Error " & Format$(Err.Number) & _
    15.             " selecting files." & vbCrLf & Err.Description
    16.             Exit Sub
    17.     End If
    18. List1.Clear
    19.     'entries = Split(CommonDialog1.FileName, vbNullChar)
    20.     entries = Split(CommonDialog1.filename, vbNullChar)
    21.  
    22.     ' See if there is more than one file.
    23.     If UBound(entries, 1) = LBound(entries, 1) Then
    24.         ' There is only one file name.
    25.         List1.AddItem entries(LBound(entries, 1))
    26.        
    27.     Else
    28.         ' Get the directory name.
    29.         dir_name = entries(LBound(entries, 1))
    30.         If Right$(dir_name, 1) <> "\" Then dir_name = dir_name & "\"
    31.  
    32.         ' Get the file names.
    33.         For i = LBound(entries, 1) + 1 To UBound(entries, 1)
    34.            
    35.             List1.AddItem dir_name & entries(i)
    36.         Next i
    37.     End If
    38.  
    39. If List1.ListCount = 0 Then GoTo ext
    40.  
    41. For X = 0 To (List1.ListCount - 1)
    42.  
    43. List1.ListIndex = X
    44. Next
    45.  
    46. FSys.GetAbsolutePathName (List1.Text)
    47. If (Len(List1.Text) > 9) Then
    48.         Dim shortname As String  ' receives short-filename equivalent
    49.         Dim slength As Long  ' receives length of short-filename equivalent
    50.  
    51.   ' Make room in the buffer to receive the 8.3 form of the filename.
    52.         shortname = Space(256)
    53.  
    54.     ' Get the 8.3 form of the filename specified.
    55.     'the file must exist for the api to do it's stuff
    56.  
    57.         slength = GetShortPathName(List1.Text, shortname, 256)
    58.     ' Remove the trailing null and display the result.
    59.  
    60.         shortname = Left(shortname, slength)
    61.       MsgBox shortname, vbInformation, "shortname"
    62.      Text1.Text = shortname
    63.  
    64.      Open "C:\fb\testbatch.bat" For Output As #1
    65.     Print #1, "c:\hd\psmd.exe" & Space(1) & Text1.Text & Space(1) & ">" & Space(1) & "C:\hB\test.Txt"
    66.            
    67. Close #1
    68.  
    69. Shell ("cmd /c C:\fb\testbatch.bat")
    70.  
    71. End if
    72. End Sub
    Thx !

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Process multiple Files

    lokiloki2,

    What is the purpose of this code:

    VB Code:
    1. For X = 0 To (List1.ListCount - 1)
    2.  
    3. List1.ListIndex = X
    4. Next
    Last edited by randem; Sep 4th, 2005 at 09:24 PM.

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Process multiple Files

    VB Code:
    1. If List1.ListCount = 0 Then GoTo ext
    There doesn't appear to be an "ext" label either.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Process multiple Files

    This allows you to select multiple filenames to open directly into the CDC.
    VB Code:
    1. Private Sub cmdOpen_Click()
    2.   ' CancelError is True.
    3.    On Error GoTo ErrHandler
    4.    ' Set Flags
    5.     CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames
    6.    ' Set filters.
    7.    CommonDialog1.Filter = "All Files (*.*)|*.*|Text" & _
    8.       "Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
    9.    ' Specify default filter.
    10.    CommonDialog1.FilterIndex = 2
    11.    ' Display the Open dialog box.
    12.    CommonDialog1.ShowOpen
    13.    ' Call the open file procedure.
    14.  '  OpenFile (CommonDialog1.FileName)
    15.    Exit Sub
    16.  
    17. ErrHandler:
    18. ' User pressed Cancel button.
    19.    Exit Sub
    20.  
    21. End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Re: Process multiple Files

    Should not have been in the code. My bad.

    If List1.ListCount = 0 Then GoTo ext

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Re: Process multiple Files

    Dglienna,

    The code you posted, will that run the .exe on each file ?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Re: Process multiple Files

    VB Code:
    1. For X = 0 To (List1.ListCount - 1)
    2.  
    3. List1.ListIndex = X
    4. Next

    Doesn't belong, was testing out some code and forgot to delete this.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Process multiple Files

    Quote Originally Posted by lokiloki2
    Dglienna,

    The code you posted, will that run the .exe on each file ?
    I'm not sure. I think it will open each one in a separate instance. I know that's the case with Word, for instance. I've never really tried to use it.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Unhappy Re: Process multiple Files

    This will not work.

    The exe I run on each file listed in the Listbox produces a checksum that I need to save to a textfile. If multiple files are selected in the CommonDialog, only the last line in the listbox gets processed. I need to process each file if someone selects more than one file.

    THX

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