> It is possible in MapBasic to retrieve a list of files within a defined
> directory ?
> 
> 
YesI got this answer from the list some time ago:

Below is a snippet of code that allows you to retrieve file names
located in a particular directory. The first argument of the FindFirstFile
API call can either be a string that specifies a valid directory or path and
filename, which can contain wildcard characters (* and ?). In my example
below I'm searching for all the Word documents (.doc) in the c:\temp
directory. Make sure you include all the constants, type and function
declarations in your MB code and also remember to release the
FindFirstFileHandle at the end!!

Hope this helps,

*******************

define MAX_PATH 260

Type FILETIME
        dwLowDateTime As Integer
        dwHighDateTime As Integer
End Type

Type WIN32_FIND_DATA
        dwFileAttributes As Integer
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Integer
        nFileSizeLow As Integer
        dwReserved0 As Integer
        dwReserved1 As Integer
        cFileName As String * MAX_PATH ' This is the 'long' file name of the
file
        cAlternate As String * 14 ' This name is in the classic 8.3
(filename.ext) filename format.
End Type

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal
lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Integer
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal
hFindFile As Integer, lpFindFileData As WIN32_FIND_DATA) As Integer
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile
As Integer) As Integer

Dim FindFileData as WIN32_FIND_DATA
Dim FindFileHandle,FindCloseResult as Integer

FindFileHandle=FindFirstFile("c:\temp\*.doc",FindFileData)

do
      print FindFileData.cFileName
loop until (NOT FindNextFile(FindFileHandle,FindFileData))

FindCloseResult=FindClose(FindFileHandle) ' release the FindFileHandle



or if you don't want to use the API:

MapBasic has no functions for getting a list of files in a directory. You
can use the Windows API, or use the following, which uses a DOS command to
get the list into a file which can then be read in MapBasic.

Dim filelist() As String
Dim counter As Integer
'get command to produce a brief (filenames only) listing to a file
Run Program "Command.com /C dir /B > files.txt"
'the OnError traps the situation where the file has not been 
'completely written
OnError Goto FILE_NOT_READY_YET
Open File "files.txt" For Input As #1
counter = 1
Do While (Not EOF(1))
ReDim filelist(counter)
Input # 1, filelist(counter)
counter = counter +1
Loop

Dialog
Title "File List"
Control ListBox
Title From Variable filelist
Control OkButton
End Program

FILE_NOT_READY_YET:
Resume 0

This section was derived from a posting by MapInfo techsupport.


Regards

Thomas Brix Lyng
Frederikshavn munincipal administration
Denmark



_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.

Reply via email to