Add throwOnMissing boolean argument to fileDelete() and directoryDelete()

Description

It would be nice to delete a file or directory and NOT have an exception thrown if the file or directory already doesn’t exist. Not only is it more code to wrap the delete in a check for existence, but even that code is prone to race conditions if two threads are removing the same file or directory, which leads to then having to wrap the delete in a try/catch which is just too much boilerplate. Furthermore, the lack of proper documented exception types for this scenario makes the catch not even possible to just catch that error leading to wide-open catch that either catches too much or looks at the message of the exception.

if( fileExists( myFile ) ) { try { fileDelete( myFile ); } catch( any e ) { if( !e.message.contains( "does not exist" ) ) { rethrow; } } }

A much better version would just be this:

fileDelete( file=myPath, throwOnMissing=false )

or

directoryDelete( path=myDir, recurse=true, throwOnMissing=false )

throwOnMissing would default to true for backwards compatibility.

 

Related Adobe CF ticket:

https://tracker.adobe.com/#/view/CF-4213740

Activity

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 31 May 2022 at 16:53
Updated 1 June 2022 at 06:15