|
-
Nov 11th, 2003, 03:22 PM
#1
Thread Starter
New Member
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:
Private Sub browseMP2File_Click()
WorkDir = GetSetting(App.EXEName, "FilePaths", "WorkDir", "")
With MP2Dialog
.FileName = ""
.DefaultExt = ".mp2"
.DialogTitle = "Select File(s)..."
.Filter = "MP2 Audio Files (*.mp2)|*.mp2|MP2 and MP3 Files (.mp2 & .mp3)|*.mp*|All Files (*.*)|*.*"
.InitDir = WorkDir
.CancelError = True
On Error Resume Next
End With
With MP2Dialog
.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoChangeDir Or cdlOFNNoDereferenceLinks Or cdlOFNFileMustExist
.ShowOpen
MP2File = MP2Dialog.FileName
MP2Text.Text = MP2File
If Err > 0 Then 'Cancel was selected
If Err = cdlCancel Then
Exit Sub
End If
'some other error occured, deal with it here!
End If
End With
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.
-
Nov 12th, 2003, 12:29 AM
#2
Hyperactive Member
Here's a class I stole from another thief to deal with your folder question.
VB Code:
Option Explicit
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Function BrowseForFolder(OwnerForm As Form) As String
Dim iNull As Integer, lpIDList As Long
Dim sPath As String, udtBI As BrowseInfo
With udtBI
'Set the owner window
.hWndOwner = OwnerForm.hwnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("Select Search Path", "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
BrowseForFolder = sPath
End Function
To use use it I use the following code
VB Code:
Private Sub cmdBrowsePath_Click()
Dim RootPath As String
Dim FolderBrowser As New clsFolderBrowser
RootPath = FolderBrowser.BrowseForFolder(Me)
Dim UserInput
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")
If UserInput = "" Then
txtDefaultPath = RootPath
Else
MkDir RootPath & "\" & UserInput
txtDefaultPath = RootPath & "\" & UserInput
End If
Set FolderBrowser = Nothing
End Sub
-
Nov 12th, 2003, 01:49 AM
#3
Thread Starter
New Member
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.
-
Nov 12th, 2003, 04:17 PM
#4
Thread Starter
New Member
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!
-
Nov 12th, 2003, 05:21 PM
#5
-= B u g S l a y e r =-
selecting multiple files sample
VB Code:
Private Sub Command1_Click()
Dim sArr() As String
Dim i As Integer
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.ShowOpen
sArr = Split(CommonDialog1.FileName, Chr(0))
For i = 0 To UBound(sArr())
Debug.Print sArr(i)
Next i
End Sub
hope that will get you going
-
Nov 12th, 2003, 05:26 PM
#6
-= B u g S l a y e r =-
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:
'- Company: PvP
'----------------------------------------
'- Notes: Browse for a folder
'
'----------------------------------------
Option Explicit
Public Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Public Const BIF_RETURNONLYFSDIRS = 1
Public Const BIF_NEWDIALOGSTYLE = &H40
Public Const MAX_PATH = 260
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
'declare variables to be used
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
'initialise variables
With udtBI
.hwndOwner = hwndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE
End With
'Call the browse for folder API
lpIDList = SHBrowseForFolder(udtBI)
'get the resulting string path
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If
'If cancel was pressed, sPath = ""
BrowseForFolder = sPath
End Function
'usage :
Private Sub Form_Click()
MsgBox BrowseForFolder(Me.hWnd, "select folder")
End Sub
-
Nov 13th, 2003, 01:24 PM
#7
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|