Results 1 to 7 of 7

Thread: Shelling multiple files (resolved!)

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Heiligenmoschel Germany
    Posts
    10

    Shelling multiple files (resolved!)

    I'm not sure if this is my first post or not... I've been digging through 1000's of post's and answered all of my questions so far. I think i'm just too tired to answer this one!!!

    I want to be able to shell multiple files. I can open a dialog.showopen box and select multiple files. (When they are selected in the bottom box they all have "" around them).

    I want to be able to shell them file by file, all in different instances. My program works for one file just fine, but in the name of lazyness i'd like to do multiple files.

    An example would be that i selected multiple .txt files and i just want to open each of them. Here's what i've got so far... I think i could cut some of it out, but i'm very new and i've hacked most of this up as best i can.


    VB Code:
    1. Private Sub browseMP2File_Click()
    2.     WorkDir = GetSetting(App.EXEName, "FilePaths", "WorkDir", "")
    3.     With MP2Dialog
    4.       .FileName = ""
    5.       .DefaultExt = ".mp2"
    6.       .DialogTitle = "Select File(s)..."
    7.       .Filter = "MP2 Audio Files (*.mp2)|*.mp2|MP2 and MP3 Files (.mp2 & .mp3)|*.mp*|All Files (*.*)|*.*"
    8.       .InitDir = WorkDir
    9.       .CancelError = True
    10.       On Error Resume Next
    11.     End With
    12.    
    13.     With MP2Dialog
    14.       .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoChangeDir Or cdlOFNNoDereferenceLinks Or cdlOFNFileMustExist
    15.       .ShowOpen
    16.    
    17.     MP2File = MP2Dialog.FileName
    18.     MP2Text.Text = MP2File
    19.  
    20. If Err > 0 Then  'Cancel was selected
    21.      If Err = cdlCancel Then
    22.        Exit Sub
    23.      End If
    24.     'some other error occured, deal with it here!
    25.    End If
    26.  End With
    27. End Sub


    Also, i want to set the WorkDir variable to a folder by browsing for the folder. I know how to browse for a file, but not a folder. Any Suggestions? Thanks!
    Last edited by ecpunk; Nov 13th, 2003 at 01:25 PM.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476
    Here's a class I stole from another thief to deal with your folder question.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type BrowseInfo
    4.     hWndOwner As Long
    5.     pIDLRoot As Long
    6.     pszDisplayName As Long
    7.     lpszTitle As Long
    8.     ulFlags As Long
    9.     lpfnCallback As Long
    10.     lParam As Long
    11.     iImage As Long
    12. End Type
    13.  
    14. Private Const BIF_RETURNONLYFSDIRS = 1
    15. Private Const MAX_PATH = 260
    16.  
    17. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    18. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    19. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    20. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    21.  
    22. Public Function BrowseForFolder(OwnerForm As Form) As String
    23.  
    24.     Dim iNull As Integer, lpIDList As Long
    25.     Dim sPath As String, udtBI As BrowseInfo
    26.  
    27.     With udtBI
    28.         'Set the owner window
    29.         .hWndOwner = OwnerForm.hwnd
    30.         'lstrcat appends the two strings and returns the memory address
    31.         .lpszTitle = lstrcat("Select Search Path", "")
    32.         'Return only if the user selected a directory
    33.         .ulFlags = BIF_RETURNONLYFSDIRS
    34.     End With
    35.  
    36.     'Show the 'Browse for folder' dialog
    37.     lpIDList = SHBrowseForFolder(udtBI)
    38.     If lpIDList Then
    39.         sPath = String$(MAX_PATH, 0)
    40.         'Get the path from the IDList
    41.         SHGetPathFromIDList lpIDList, sPath
    42.         'free the block of memory
    43.         CoTaskMemFree lpIDList
    44.         iNull = InStr(sPath, vbNullChar)
    45.         If iNull Then
    46.             sPath = Left$(sPath, iNull - 1)
    47.         End If
    48.     End If
    49.  
    50.     BrowseForFolder = sPath
    51.    
    52. End Function
    To use use it I use the following code
    VB Code:
    1. Private Sub cmdBrowsePath_Click()
    2.     Dim RootPath As String
    3.     Dim FolderBrowser As New clsFolderBrowser
    4.  
    5.     RootPath = FolderBrowser.BrowseForFolder(Me)
    6.  
    7.     Dim UserInput
    8.     UserInput = InputBox("Do you want to create a new folder here?" & vbCrLf & "If so, type the folder name and click OK." & vbCrLf & "If not, then click Cancel and the current folder will be used.", "Create Folder")
    9.     If UserInput = "" Then
    10.         txtDefaultPath = RootPath
    11.     Else
    12.         MkDir RootPath & "\" & UserInput
    13.         txtDefaultPath = RootPath & "\" & UserInput
    14.     End If
    15.     Set FolderBrowser = Nothing
    16. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Heiligenmoschel Germany
    Posts
    10
    Thats great about the folder stuff... I need to study up some more. I have no idea what most of that says!!! But i can make anything work.

    I'm still looking for some info about the multiple file thing. I have an idea about how to do it, but it is sort of a lot of work.

    I'm not sure how I would pass all of the file names in "file1" "file2" "file3" to something, maybe a list, and then sort them out from there. I think that i should use an array after that(i don't know how to use them, but i've got the idea of what they do) to break it down, remove the "" and send them one by one to the shell. And I guess a DoEvents would work between each one. Thats what I'm thinking so far, but if anyone has a better way be sure to let me know!

    Thanks.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Heiligenmoschel Germany
    Posts
    10
    I've made lots of progress... just not with this. I learned how to use the ShellandWait function that i found on here. So... Still working on my app, trying to get everything to work, but as far as this problem, it still remains a mystery!

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    selecting multiple files sample

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim sArr() As String
    3.     Dim i As Integer
    4.     CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
    5.     CommonDialog1.ShowOpen
    6.     sArr = Split(CommonDialog1.FileName, Chr(0))
    7.     For i = 0 To UBound(sArr())
    8.         Debug.Print sArr(i)
    9.     Next i
    10. End Sub

    hope that will get you going
    -= a peet post =-

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    the browse for folder routine can be modified to use the new style of browser. (the one wtith the make new folder button)

    VB Code:
    1. '- Company: PvP
    2. '----------------------------------------
    3. '- Notes:   Browse for a folder
    4. '      
    5. '----------------------------------------
    6. Option Explicit
    7.  
    8. Public Type BrowseInfo
    9.      hwndOwner As Long
    10.      pIDLRoot As Long
    11.      pszDisplayName As Long
    12.      lpszTitle As Long
    13.      ulFlags As Long
    14.      lpfnCallback As Long
    15.      lParam As Long
    16.      iImage As Long
    17. End Type
    18.  
    19. Public Const BIF_RETURNONLYFSDIRS = 1
    20. Public Const BIF_NEWDIALOGSTYLE = &H40
    21.  
    22. Public Const MAX_PATH = 260
    23. Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    24. Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    25. Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    26. Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    27.  
    28. Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
    29.      
    30.     'declare variables to be used
    31.      Dim iNull As Integer
    32.      Dim lpIDList As Long
    33.      Dim lResult As Long
    34.      Dim sPath As String
    35.      Dim udtBI As BrowseInfo
    36.  
    37.     'initialise variables
    38.      With udtBI
    39.         .hwndOwner = hwndOwner
    40.         .lpszTitle = lstrcat(sPrompt, "")
    41.         .ulFlags = BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE
    42.      End With
    43.  
    44.     'Call the browse for folder API
    45.      lpIDList = SHBrowseForFolder(udtBI)
    46.      
    47.     'get the resulting string path
    48.      If lpIDList Then
    49.         sPath = String$(MAX_PATH, 0)
    50.         lResult = SHGetPathFromIDList(lpIDList, sPath)
    51.         Call CoTaskMemFree(lpIDList)
    52.         iNull = InStr(sPath, vbNullChar)
    53.         If iNull Then sPath = Left$(sPath, iNull - 1)
    54.      End If
    55.  
    56.     'If cancel was pressed, sPath = ""
    57.      BrowseForFolder = sPath
    58.  
    59. End Function
    60.  
    61.  
    62. 'usage :
    63. Private Sub Form_Click()
    64.     MsgBox BrowseForFolder(Me.hWnd, "select folder")
    65. End Sub
    -= a peet post =-

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Heiligenmoschel Germany
    Posts
    10
    Peet, that's awesome. Just what i was looking for in both cases. At first when i looked at it it was a bit much for me, but then i just thew it in a form and dug through it. Vielen Dank! I'll go ahead and call this one resolved!

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