Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GETFILE() - Select Multiple Files
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01351917
Message ID:
01351990
Vues:
39
How do you select multiple files while Open File Dialog box is opened?
**************************************************
*-- Class:        acxcommondialog
*-- ParentClass:  olecontrol
*-- BaseClass:    olecontrol
*-- Time Stamp:   09/21/07 04:23:01 PM
*-- OLEObject = C:\WINDOWS\system32\comdlg32.ocx
*
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform