Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple Select GetFile function
Message
From
05/06/2008 10:48:08
 
 
To
05/06/2008 09:21:04
Stan Vaninger
Mitek Industries, Inc
Missouri, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01321835
Message ID:
01321872
Views:
46
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:
**************************************************
*-- Class:        acxcommondialog 
*-- ParentClass:  olecontrol
Define Class acxcommondialog As OleControl
  Height = 37
  Width = 36
  *-- XML Metadata for customizable properties
  _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>]
  *-- The folder from which the file(s) were selected
  cpath = (Fullpath( Curdir() ))
  *-- Caption for the open file dialog
  ccaption = "Select one or more files"
  *-- Default file extension to use if the user types something in the box that does not have an extension
  cextension = ""
  *-- The list of selected files from the dialog
  cselectedfiles = ""
  *-- Types of files to display such as Tables | *.dbf
  cfilter = ""
  Name = "acxcommondialog"

  *-- sets the required flags, displays the dialog and parses the return values
  Procedure getfiles
    #Define cdlOFNReadOnly  1  && Checks Read Only check box for Open and Save As dialog boxes.
    #Define cdlOFNOverwritePrompt  2  && Generates a message box if the selected file already exists.
    #Define cdlOFNHideReadOnly  4  && Hides the Read Only check box.
    #Define cdlOFNNoChangeDir  8  && Sets the current directory to what it was when the dialog box was invoked.
    #Define cdlOFNHelpButton  16  && Causes the dialog box to display the Help button.
    #Define cdlOFNNoValidate  256  && Allows invalid characters in the returned file name.
    #Define cdlOFNAllowMultiselect  512  && Allows the File Name list box to have multiple selections.
    #Define cdlOFNExtensionDifferent  1024  && Extension of returned file name is different from the one set by DefaultExt.
    #Define cdlOFNPathMustExist  2048  && User can enter only valid path names.
    #Define cdlOFNFileMustExist  4096  && User can enter only names of existing files.
    #Define cdlOFNCreatePrompt  8192  && Asks if the user wants to create a file that does not currently exist.
    #Define cdlOFNShareAware  16384  && Sharing violation errors will be ignored.
    #Define cdlOFNNoReadOnlyReturn  32768  && The returned file will not have the Read Only attribute set.
    #Define cdlOFNNoLongNames  262144  && No long filenames.
    #Define cdlOFNExplorer  524288  && Windows 95 Open A File dialog box template.
    #Define cdlOFNNoDereferenceLinks  1048576  && No shortcuts.
    #Define cdlOFNLongNames  2097152  && Long filenames.

    Local lcCurDir, lnFlags, lcFiles, lnI
    *** Save the current directory
    lcCurDir = Fullpath( Curdir() )
    *** Set the required flags
    *** This demo uses the common dialog to allow users to select
    *** multiple files. You could easily modify this class to be totally
    *** configurable and use it for all your getfile() and putfile() dialogs
    *** simply by adding properties for each of thes configurable options
    *** and setting the flags depending on their values
    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
      *** Display the dialog
      .ShowOpen()
      *** If multiple files were selected, .FileName consists of the path followed by a
      *** separator followed by the list of files selected separated by separators. If
      *** only one file was selected, .FileName is the complete path to the file.
      lcFiles = .FileName
      *** Individual files are separated with .NULLS.
      *** so if we have any in the string returned
      *** we know that we have more than one file
      If Chr( 0 ) $ lcFiles
        *** But we have to replace all the nulls with
        *** another character because GETWORDNUM() does
        *** not see nulls as separators - do not use a space
        *** in case there are spaces in file or folder names
        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
    *** restore current directory
    Cd ( lcCurDir )
  Endproc
Enddefine
And here is an example of how to use it:
*-- Form:         commondialogdemo
*-- ParentClass:  form
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform