Hi Sann
I got this from the list some time ago, but I have never use it:
'*************************** Solution start *******************************
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
'*************************** Solution end *******************************
Or if you don't know the dir you could try this work-a-round form MapInfo
Tech support:
'*************************** Solution start *******************************
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.
'*************************** Solution end *******************************
Regards
Thomas Brix Lyng
Frederikshavn Municipal Administration
Denmark
> ----------
> Fra: sann[SMTP:[EMAIL PROTECTED]]
> Sendt: 24. juli 2002 09:53
> Til: [EMAIL PROTECTED]
> Emne: MI-L : FindFile Through MapBasic
>
>
> Hi,
> Lister
>
> I Want to find file through MapBasic . I tried the
> Imagehelp.dll but when application running it
> crasing mapinfo.
>
> Sann
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Health - Feel better, live better
> http://health.yahoo.com
>
> ---------------------------------------------------------------------
> List hosting provided by Directions Magazine | www.directionsmag.com |
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]