This will move a given file:
Rename File old_filespec As new_filespec
But remember to rename all the files that make up af MapInfo table, if it is tables.
If it is MapInfo tables you could also use :
Rename Table table As "newtablespec"
To find the files in a certain folder you need the WINAPI functions to do this:
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
and the datatype and definitions:
Define INVALID_HANDLE_VALUE -1
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
cAlternate As String * 14
End Type
FindFirst finds the first file that matches the search parameters, FindNext will find
the next and return INVALID_HANDLE_VALUE when no more files were found. Use FindClose
to End the search.
Something like this:
Function APIGetFilesInDirectory (ByVal szPath As String, ByVal szFilespec As String,
szarrList() As String) As Logical
Dim hFindFile, nStatus As Integer,
f As WIN32_FIND_DATA,
nFileNum As integer
OnError GoTo ErrorOccured
APIGetFilesInDirectory = FALSE
Print "szPath: " + szPath
Print "szFilespec: " + szFilespec
hFindFile = FindFirstFile (szPath + szFilespec, f)
If hFindFile <> INVALID_HANDLE_VALUE Then
Do
Print "Found file: " & f.cFilename & ", " & f.dwFileAttributes
nFileNum = nFileNum + 1
ReDim szArrList(nFileNum)
szArrList(nFileNum) = f.cFilename
nStatus = FindNextFile (hFindFile, f)
Loop While nStatus = 1
End If
nStatus = FindClose (hFindFile)
APIGetFilesInDirectory = TRUE
Exit Function
'-------------------------
ErrorOccured:
Note ERR_ERRORMSG & lf & Error$()
End Function
Peter Horsb�ll M�ller
GIS Developer
Geographical Information & IT
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
Tel +45 6311 4900
Direct +45 6311 4908
Mob +45 5156 1045
Fax +45 6311 4949
E-mail [EMAIL PROTECTED]
http://www.cowi.dk
-----Original Message-----
From: Rena Jones [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 14, 2004 3:36 PM
To: [EMAIL PROTECTED]
Subject: MI-L Relocate files to new directory
Hi all,
Is there a way in MapBasic to search in a folder for a certain text string within a
file name, and if it finds it, to move the file to a new directory?
I have folders with many files--and because the text I am interested in is at the end
of the file name, sorting the directory doesn't help me to organize them --and I can't
do the relocation of files by hand without a lot of work.
I have used rename,kill,register, etc., but can't find anything in the Help about
actually moving a file.
Thanks in advance!
RJ
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe,
e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 12602