Does anyone know of a function that replaces the GetFile() and allows the user to select multiple files?Here is a custom sub-class of the common dialog to handle this:
Define Class acxcommondialog As OleControl
Height = 37
Width = 36
_MemberData = [<VFPData><memberdata name="cpath" type="property" display="cPath"/><memberdata name="getfiles" type="method" display="getFiles"/><memberdata name="ccaption" type="property" display="cCaption"/><memberdata name="cextension" type="property" display="cExtension"/><memberdata name="cselectedfiles" type="property" display="cSelectedFiles"/><memberdata name="cfilter" type="property" display="cFilter"/></VFPData>]
cpath = (Fullpath( Curdir() ))
ccaption = "Select one or more files"
cextension = ""
cselectedfiles = ""
cfilter = ""
Name = "acxcommondialog"
Procedure getfiles
#Define cdlOFNReadOnly 1
#Define cdlOFNOverwritePrompt 2
#Define cdlOFNHideReadOnly 4
#Define cdlOFNNoChangeDir 8
#Define cdlOFNHelpButton 16
#Define cdlOFNNoValidate 256
#Define cdlOFNAllowMultiselect 512
#Define cdlOFNExtensionDifferent 1024
#Define cdlOFNPathMustExist 2048
#Define cdlOFNFileMustExist 4096
#Define cdlOFNCreatePrompt 8192
#Define cdlOFNShareAware 16384
#Define cdlOFNNoReadOnlyReturn 32768
#Define cdlOFNNoLongNames 262144
#Define cdlOFNExplorer 524288
#Define cdlOFNNoDereferenceLinks 1048576
#Define cdlOFNLongNames 2097152
Local lcCurDir, lnFlags, lcFiles, lnI
lcCurDir = Fullpath( Curdir() )
lnFlags = cdlOFNExplorer +;
cdlOFNHideReadOnly +;
cdlOFNAllowMultiselect +;
cdlOFNPathMustExist +;
cdlOFNFileMustExist
With This
.Flags = lnFlags
.DialogTitle = .ccaption
.Defaultext = .cextension
.InitDir = .cpath
.Filter = .cfilter
If Not Empty( .Filter )
.FilterIndex = 1
Endif
.ShowOpen()
lcFiles = .FileName
If Chr( 0 ) $ lcFiles
lcFiles = Strtran( lcFiles, Chr( 0 ), [~], 1, -1, 1 )
.cpath = Getwordnum( lcFiles, 1, [~] )
Else
.cpath = Addbs( Justpath( lcFiles ) )
Endif
lcFiles = Alltrim( Strtran( lcFiles, .cpath, [], 1, 1, 1 ) )
.cselectedfiles = []
For lnI = 1 To Getwordcount( lcFiles, [~])
.cselectedfiles = .cselectedfiles + Addbs( .cpath ) + Getwordnum( lcFiles, lnI, [~] ) + Chr( 13 ) + Chr( 10 )
Endfor
Endwith
Cd ( lcCurDir )
Endproc
Enddefine
And here is an example of how to use it:
Define Class commondialogdemo As Form
Top = 0
Left = 0
Height = 500
Width = 650
DoCreate = .T.
Caption = "Select Multiple Files Using the Common Dialog"
AllowOutput = .F.
Name = "CommonDialogDemo"
Add Object edtselectedfiles As EditBox With ;
FontName = "Comic Sans MS", ;
FontSize = 16, ;
Height = 419, ;
Left = 25, ;
Top = 13, ;
Width = 610, ;
Name = "edtSelectedFiles"
Add Object odialog As acxcommondialog With ;
Top = 453, ;
Left = 586, ;
Height = 37, ;
Width = 36, ;
cfilter = "Tables | *.dbf", ;
Name = "oDialog"
Add Object cmdselectfiles As CommandButton With ;
Top = 448, ;
Left = 192, ;
Height = 35, ;
Width = 266, ;
FontName = "Comic Sans MS", ;
FontSize = 16, ;
Caption = "Select Tables to Process", ;
Name = "cmdSelectFiles"
Procedure Init
Thisform.edtselectedfiles.ControlSource = [Thisform.oDialog.cSelectedFiles]
Endproc
Procedure cmdselectfiles.Click
Thisform.odialog.getFiles()
Thisform.edtselectedfiles.Refresh()
Endproc
Enddefine