Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getfile()
Message
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00553365
Message ID:
00553385
Views:
20
>>I have an application that uses the getfile method to let the user choose a file. If I know where the directory resides, can I use the getfile() to point to the directory I want, if so how?
>>
>> Is there another way to do this?
>
>The Common Dialog ActiveX control allows you to specify the directory without changing the current default. It's uses the same DLL that GETFILE() does to produce the dialog.

Here is the example, which allows to choose multiple files. It also allows to start from some directory:
************************************************************
function File_Chooser
*  Description...... : Function invokes MS Common Dialog Control and
*                          : returns an array of files via parameters list.
*                    : Each element of the array contains one file...
*  Calling Samples...: dimension a_File[1]
*                    : lcPath = ""
*                    : lnFiles = File_Chooser(@a_File, @lcPath, DTitle, InDir)
*  Parameter List....: a_File, pPath, DTitle, InDir
*  Created by George Tasker and modified by Nadya Nosonovsky
********************************************************************
lparameter a_File, tcPath, DTitle, InDir
external array a_File
** Definition of Common Dialog flags
#define cdlOFNAllowMultiselect 0x200
*!*     Specifies that the File Namelist box allows multiple selections.
*!*     The user can select more than one file at run time by pressing
*!* the SHIFT key and using the UP ARROW and DOWN ARROW keys to select the desired files.
*!* When this is done, the FileName property returns a string containing the names
*!*     of all selected files.
*!* The names in the string are delimited by spaces.
local oDialog, lcFileName
oDialog = createobject('MSComDlg.CommonDialog')
with oDialog
* Set the flags for Multi-Select/Explorer
     .MaxFileSize = 260
     .Flags = 0x200 + 0x80000
     .DialogTitle=DTitle
* Set filters
     .filter = "All Files (*.*)|*.*|Database Files (*.dbf)|*.dbf|Index Files (*.cdx)|*.cdx"
* Specify default filter
     .FilterIndex = 1

     if not empty(m.InDir)
          .InitDir=InDir
     endif
     .ShowOpen
* Save the file name to a variable
     lcFileName = .FileName
endwith
oDialog = null
if empty(m.lcFileName) && User pressed a Cancel
     return 0
endif
local lnPt, lnFiles, lni, lcName
lnPt = at(chr(0), m.lcFileName)
if lnPt > 0
     tcPath = left(m.lcFileName, m.lnPt - 1)
     lcFileName = substr(m.lcFileName, m.lnPt + 1)
     lnFiles = occurs(chr(0), m.lcFileName) + 1
     dimension a_File[m.lnFiles]
     lni = 0
     do while not empty(m.lcFileName)
          lni = m.lni + 1
          lnPt = at(chr(0), lcFileName)
          if lnPt > 0
               lcName = left(m.lcFileName, m.lnPt - 1)
               lcFileName = substr(m.lcFileName, m.lnPt + 1)
          else
               lcName = m.lcFileName
               lcFileName = ""
          endif
          a_File[m.lni] = m.lcName
     enddo
     lnFiles = alen(a_File, 1)
*!*       FOR lni = 1 TO lnlast
*!*         ? a_file[lni]
*!*       NEXT
else
     lnFiles=1
     dimension a_File[m.lnFiles]
     lnPos=rat('\',m.lcFileName)
     tcPath=justpath(m.lcFileName)
     lcName=justfname(m.lcFileName)
     a_File[1] = lcName
endif
return m.lnFiles
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform