IonicWind Software

IWBasic => General Questions => Topic started by: Brian on November 02, 2010, 10:10:49 AM

Title: Deleting Files
Post by: Brian on November 02, 2010, 10:10:49 AM
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
Title: Re: Deleting Files
Post by: WayneA on November 02, 2010, 10:16:07 AM
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.
Title: Re: Deleting Files
Post by: Brian on November 02, 2010, 10:47:32 AM
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
Title: Re: Deleting Files
Post by: WayneA on November 02, 2010, 11:00:55 AM
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.
Title: Re: Deleting Files
Post by: Brian on November 02, 2010, 11:38:44 AM
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