DeleteFile.. doesn't

BlitzMax Forums/BlitzMax Programming/DeleteFile.. doesn't

Gabriel(Posted 2006) [#1]
Not suggesting this is a bug, I'm quite sure it's not, but I do need to find a way around this. This goes back to my thread about zlib and passwords. Since there is apparently no way to zip a bank with a password, I'm having to write temp files to disk, archive them and delete the archives. Doesn't really matter, since the end user won't have any of my tools and I can read them straight into memory without unpacking to disk.

However, I can't get the files to delete when I'm finished with them. I've closed the streams, closed the archives, everything is finished with, but deletefile doesn't delete them.

I don't know why this is happening, but I'm guessing it might be because the program is trying to delete too quickly after closing the stream and the file is not available for deletion for a few milliseconds. It's a long export process so I don't really care about waiting a few millisecs until the file is ready for deletion, but is there a proper way to do this? ( Other than trying over and over and seeing if it worked with filetype. )

Failing that, is there a more powerful way to delete a file? I recall that there was a little program you could download which had shell integration, and you could delete any file by selecting this program on the right click menu. Files that normally would refuse to delete with some kind of "this file cannot be renamed or deleted as it is currently being used by a program" just went bye-bye. Any idea how they work?

Is there any way of detecting when they are suitable


skidracer(Posted 2006) [#2]
Hmm, I don't want to sound boring but it took me less time to test the following than to read your post:
f=WriteFile("test.txt")
WriteLine f,"hello"
CloseFile f
DeleteFile "test.txt"



Gabriel(Posted 2006) [#3]
Yeah, it's a bit more complicated than that though. I'm using GMan's ZipEngine and writing some pretty big files. I write several big files ( 4-5MB ) and then archive them into one big zip. Then I delete the files, except that I don't.

There's no possibility of user error, I've stepped through the code, I've got debuglog calls, and I don't even begin to delete the first file until I've archived the final file and closed the archive.

So, not sure what it is, but maybe it's because ZLib isn't finished with the file even when BlitzMax has control again.


PantsOn(Posted 2006) [#4]
i've had a problem when even after closing a file off. it still takes time for windows to "create" the file.
In the meantime you already deleted a file thats not there, and then the file gets created.

try something like
while not deletefile(tempfile)
delay 100
wend


Gabriel(Posted 2006) [#5]
Yep, that's pretty much what I'm doing at the moment. Just wondered if there was a better way, but I guess that's good enough, particularly since I'm the only person using the program.


skidracer(Posted 2006) [#6]
A few things to try, comment out the chmod fix for deleting readonly files pub.mod/stdc.mod/stdc.c[46]. If that doesn't help try changing line 48 to _unlink( path );

This sounds a lot like a virus checker or search tool (google desktop?) messing with files externally, are you using the proper windows user temp folder?