Hello Hans
You probably won't like the details Hans.
There is a documented bug with "Add Column" that I had logged with MI Tech
Support in Nov 2001 (#19823 temporary files created, but not being deleted).
MI will never delete the .tmp files created with that command. Eventually,
your Temp directory contains 9999 files and MI dies. This could take place
in a single application run if large numbers of .tmp files are being
created. It could take months with small applications that just create a
few of these .tmp files.
I checked with MI Tech Support this past April and the bug had not been
fixed. It has been in all versions of MI since at least 5.0.
There does not seem to be an acceptable solution to this problem. MI tech
support suggested that I write a script to delete all the .tmp files before
running a utility or perhaps after it ends. There are many reasons why this
is difficult or not a good idea:
- One has to use API to collect the .tmp names and delete them since the
MB Kill command only operates on a single file.
- As noted above, it is possible to create more that 10,000 temp files in
a single run - deleting the *.tmp files during a run could result in a crash
since it would be possible to delete files still in use.
- Other copies of MI could be running and using their own .tmp files which
you would not want to delete.
- etc.
I have used the delete .tmp files approach in one application. If you make
sure you only have one copy of MI running and it has just opened (no .tmp
files yet), then you can clear the Temp directory. The code below is what I
used. I'm sure you can make it better.
What you really need is a work-around for the Add Column statement
Lorne
' ************ '
' WINDOWS API FUNCTION DECLARATIONS
' to allow access to the system
' File Finding utilities
' ************ '
Define MAX_PATH 260
Define ERROR_NO_MORE_FILES 18
Define INVALID_HANDLE_VALUE -1
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
cAlternate As String * 14
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
' Delete File API
Declare Function DeleteFile Lib "Kernel32.dll" Alias "DeleteFileA" (byVal
lpFileName As String) As Integer
Declare Sub Main()
Declare Sub FilesToArray(ByVal FileSpec As String, FileNames() As String)
Declare Sub DeleteFiles (Path as String, FileNames() as String)
Declare Function StripNulls(OriginalString As String) As String
Sub Main()
Dim FileNames() as String
' Clear the Windows Temp directory.
' Note: Mapinfo does not have a file KILL command that can handle
wildcards.
' Use the Windows API
Temp_Directory = PathToDirectory$(TempFileName$(""))
Call FilesToArray (Temp_Directory + "~MAP*.TMP", FileNames)
Call DeleteFiles (Temp_Directory, FileNames)
ReDim FileNames(0) ' Release the memory
End Sub
' ************ '
Sub FilesToArray(ByVal FileSpec As String, FileNames() As String)
Dim lRet As Integer
Dim handle As Integer
Dim FindData As WIN32_FIND_DATA
Dim FileName As String
Dim fileCount As Integer
ReDim FileNames(0)
FileCount = 0
' the FileSpec argument can contain wildcards, e.g. "C:\*.doc")
' start the searching, exit if no file matches the spec
handle = FindFirstFile(FileSpec, FindData)
If handle < 0 Then
Exit Function
End If
Do
If FindData.dwFileAttributes = 32 Then
' 32 = File that can be deleted... NOT read only.
' get this entry's name
FileName = FindData.cFileName
' Get rid of any NULL characters
FileName = StripNulls(FileName)
' add this entry to the result
fileCount = fileCount + 1
If fileCount > UBound(FileNames) Then
' make room in the array if necessary
ReDim FileNames(FileCount + 100)
End If
FileNames(fileCount) = FileName
End If
' read the next file, returns zero when there are no more files
lRet = FindNextFile(handle, FindData)
Loop While lRet = 1
' stop enumeration
lRet = FindClose(handle)
' discard unused array items and return to caller
ReDim FileNames(FileCount)
End Sub
' ************ '
Function StripNulls(OriginalString As String) As String
Dim Null_Position as Integer
Null_Position = InStr(1, OriginalString, Chr$(0))
If Null_Position > 0 Then
OriginalString = Left$(OriginalString, Null_Position - 1)
End If
StripNulls = OriginalString
End Function
' ************ '
Sub DeleteFiles (Path as String, FileNames() as String)
Dim Counter as Integer
Dim ReturnValue as Integer
For Counter = 1 to ubound( FileNames)
' Mapbasic "Kill" gernerates an error on locked files and one
' cannot bypass the message via the OnError routine.
' Use the Win API
'
' Kill Path + FileNames(Counter)
ReturnValue = DeleteFile (Path + FileNames(Counter))
Next
End Sub
' ************ '
-----Original Message-----
From: Hans Wapenaar [mailto:[EMAIL PROTECTED]
Sent: December 6, 2005 4:14 AM
To: Lorne
Subject: Re: [MI-L] temp files not removed
Yes indeed, I am using add column in my mapbasic application twice.
Coincidence or not: there are also two temp files for each process that
mapinfo is not removing at all. So I think you are right! Can you forward me
the details?
Thanks a lot
Hans Wapenaar
[EMAIL PROTECTED]
----- Original Message -----
From: "Lorne" <[EMAIL PROTECTED]>
To: "'Hans Wapenaar'" <[EMAIL PROTECTED]>
Sent: Saturday, December 03, 2005 1:13 PM
Subject: RE: [MI-L] temp files not removed
> Hello Hans
>
> Are you using the "Add Column" command? If so, there is a
documented error
> concerning that command and I can forward details to you.
>
> Lorne
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
Hans
> Wapenaar
> Sent: November 29, 2005 10:40 AM
> To: [email protected]
> Subject: [MI-L] temp files not removed
>
>
> Hi,
>
> I have written an mapbasic application that is generating map in
batch.
> Unfortunately the application generates loads of tmp files.
Probably more
> than the limit of 10000. At a certain moment mapinfo generates
an error. I
> found out that 'close all' is not removing all tmp files. Some
files remain
> on the disk. Also: the numbering continues where it has stopped.
So when the
> first batch generate 500 tmp files. the next batch starts with
tmp file 501,
> even when several tmpfiles are removed.
>
> Anyone an idea how to manage these temp files? Tips to reduce
the amount of
> remove them during a process?
>
> Hans Wapenaar
> [EMAIL PROTECTED]
_______________________________________________
> MapInfo-L mailing list
> [email protected]
> http://www.directionsmag.com/mailman/listinfo/mapinfo-l
>
>
_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l