Delete file using FileManager?

Would it be possible to add a delete(path) function to ’FileManager` so that we can delete files from a script?

Perhaps through a Workflow delete action ?

( The intersection of ‘script’ and ‘delete’ can be quite a dangerous place )

What is the use case you’re thinking of? Is it for active file management or for removing temporary or cached data? There may be safer alternatives.

Since I don’t know how to store a token in Credential I’m currently storing it in a file using FileManager. The service that requires this token might invalidate it. I would like to delete the file when that happens (instead I currently write an empty string to that file).

I’d just use a dot file with your existing approach. Out of sight out of mind. Can’t be more than a few hundred bytes.

1 Like

Did not think of starting the name with a dot. Good suggestion! Thanks.

1 Like

I’d be interested in delete support as well. I have an action to save out files with a specific set of tags. Periodically, I like to update the saved files to match whats in drafts. It would be nice to be able to delete the folder first, before saving the new files, to handle drafts that have been removed and I’d like to delete from the Drafts folder as well.

I handle this manually now, periodically deleting the folder from the Files app, and then saving again. It would be nice to have support for automating this, edven knowing that deleting from scripts can be a dangerous combination.

I would love the ability to delete folders with FileManager. I’m setting up my blogging workflow in Drafts and I auto-create Draft specific folders using the UUID under Libarary/Previews/images to make it easier for me to later delete them without deleting images for Drafts I’m currently working on. I’d love to have a one-button purge action that just deletes the whole folder matching the current Draft UUID.

+1 for file deletion with the FileManager. I get that it could be risky and cause inadvertent data loss for unsuspecting users, but definitely something for more seasoned people.

Not impossible I would add delete functions, but in the meantime I would suggest it’s a good strategy to move items you wish to designate for deletion to a trash or to-be-deleted folder.

1 Like

That was actually going to be my workaround, combined with some other external automation that would periodically clear the file, but even as a best practice, what you’re saying makes a lot of sense.

I will add the @sylumer has actually solved this in his ThoughtAsylum TADpoLe library and the scripting is deliciously simple:
fm.moveItem(p_strFilePath, null, true);

Well, it used to work.

At some point it started producing files called "null " for me instead. I used it that infrequently, I don’t know when it changed or what changed.

I haven’t yet figured out an alternative yet that works cross platform. Still on my “list” to figure something out for that.

On the Mac, you can just use a shell command.

Guess it was too good to be true :grinning:

I guess renaming the file as null will still simplify purging the files from another source as well.