Subject Re: check to see if a file is in a dir before deleting it
From Mervyn Bick <invalid@invalid.invalid>
Date Sun, 18 Apr 2021 21:57:54 +0200
Newsgroups dbase.getting-started

On 2021/04/18 20:51, Charlie wrote:
> I am trying to check to see if a file actually exists in a particular directory before deleting it.  I can not figure this out.
>
> The only thing I have tried is:
>
> if xcsv+"\etext"+ltrim(str(ebno))+".csv" = true
>       msgbox( "Success" )
>    endif
>
> Which is a futile attempt I realize.
>
> Instead of the message box success I would delete it if it exists with this:
> delete file xcsv+"\etext"+ltrim(str(ebno))+".csv"
>
> I don't seem to be able to figure out a try, catch to do it.
>
> I realize this is not much info but I don't have much to give.  Any suggestions?
>
> Charlie
>


cFile ='d:\path\whatever.csv' //for a different folder
or
cFile = 'whatever.csv' // for the working folder

if file(cFile)
    new File().delete(cFile)
endif


If necessary you can build up the contents of cFile so that ? cFile
shows d:\path\whatever.csv or whatever.csv as appropriate.

Mervyn.