Iterating selected files from dialog box
I have a very genuine query with me, which I want to ask you experts to solve it for me. Basically I want to iterate process over selected files, what are they? The selected files are from dialog box. Please help me to iterate them. The below code I have used to count selected files:
Code:
Dim dlg as OpenDialog
Dim f as FolderItem
dlg=New OpenDialog
dlg.Title="Select file(s)"
dlg.MultiSelect = True
f=dlg.ShowModal()
MsgBox("dlg.Count = " + Str(dlg.Count)) /// shows the count of files selected
Re: Iterating selected files from dialog box
Just have a look at COUNT and TRUE ITEM, if you get zero then it’s confirmed that the file in the FolderItem is not a directory. If it contains no file than its not a directory. The below code will do it for you:
Code:
if f.count>0 then
for i=0 to f.count-1
f2=f.trueitem(i)
next i
end if
Actually, you have to create a recursive procedure if you have sub directories in the directories.
Re: Iterating selected files from dialog box
I drove my self into the same problem that is having sub directories under directories, which becomes tricky for us to handle. Also my set back was that RealBasic application pretends that it can select multiple lines in the fileopen dialog box but it doesn’t. It only makes us think that and it only returns only one. The other application that allows one file to be selected will allow only one to be highlighted in the dialog box. So REALbasic is bug to me. The problem is with RB2008 and RB2009
Re: Iterating selected files from dialog box
Language suggestion that tells us about property MultiSelect are:
- If True, the dialog supports multiple selections of files.
- The default is false.
- ShowModal still returns a FolderItem, but the FolderItem returned will be the first selection in the case of a MultiSelect OpenDialog.
- For a list of all selected FolderItems, it has added an element (zeroBasedIndex As Integer).
- With the Count as integer property it has FolderItem property along.
Re: Iterating selected files from dialog box
The below code I have personally tested by myself and its working fine with me. But remember that the following code is tested only on windows. If you have different operating system then it might differ.
Code:
Dim dlg AS OpenDialog = New OpenDialog
Dim ffile AS FolderItem
dlg.MultiSelect = True
ffile = dlg.ShowModal()
for i As Integer = 0 to dlg.Count-1
ffile = dlg.item(i)
If ffile.exists Then
'Do something with the file
End If
next
Re: Iterating selected files from dialog box
I have done many researches over the internet and came to conclusion that the REALbasic OpenDialog Folderitem multiselect option does not work properly. I wonder why it doesn’t because its documentation reports that it is a feature of it. Actually I am a new to REALbasic but competent to Applescripter. Currently I have created an Applescript that will display identical file selection dialog box as REALbasic. But you can select more than one file at a time. The disadvantage would be that the names of the files that have to be returned to their regular budget proposal as a value of comma-delimited string, but this is easily converted into a string array of filenames, which can give RB code for that.
Re: Iterating selected files from dialog box
Try the below code in your actual source code. It would allow the names of the files to return to there regular string. It is based on REALbasic, it will work properly.
Code:
Option Compare Database
Option Explicit
Private Sub cmdFileDialog_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Clear the list box contents.
Me.FileList.RowSource = ""
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow the user to make multiple selections in the dialog box.
.AllowMultiSelect = True
' Set the title of the dialog box.