October 30, 2025, 11:16:20 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Deleting Files

Started by Brian, November 02, 2010, 10:10:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hi,

I need to delete some zero-length files from a directory. They are created by my
program whenever it happens to create files that eventually have nothing written
to them, and can be discarded

Any ideas?

Brian

WayneA

Make sure the file is closed and use DeleteFile
INT = DELETEFILE(name as STRING)


Shouldn't be a problem with 0 length files. If you need to check the file lengths just open them and Len() the file variable.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

Brian

Wayne,

Thanks for the quick reply. What was happening is that filelen wasn't working on the intended file,
because (I think) of the double "\\" it needs. But DELETEFILE works without the double slashes

Take out the IF and ENDIF lines and DeleteFile works

   filelen=LEN(pathandname+"_5 FOBS.TXT")
IF filelen=0
   DeleteFile(pathandname+"_5 FOBS.TXT")
ENDIF

Hmmm, how to get round that...

Brian

WayneA

Open the file with OpenFile then use Len on the File variable, rather then the file path string. Checking the path string will only return the length of the string which will never be 0.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

Brian

Wayne,

That cracked it. I'm checking the file length before using CLOSEFILE
If it's zero after closing, then DELETEFILE works OK

Thanks for a fresh pair of eyes...

Brian