How to know if filedelete deleted a file?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

How to know if filedelete deleted a file?

09 Jun 2021, 11:35

In my script, I need to clean up some files in a directory, so I use filedelete to delete them if they exist (they may not).
I'm logging the deletions, so how can I tell if a file was actually deleted?

filedelete, %whatfile%
if(errorlevel = 0)
;log that the file was deleted

If no file was deleted, I don't want to log it.

I'm looking at the docs, but can't figure out what to do.

This seems to be the value of errorlevel
returns 0 if it deletes the file
returns 1 if there is no file
returns 0 if a wildcard is used
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: How to know if filedelete deleted a file?

09 Jun 2021, 11:42

FileExist is a safe bet. If you check beforehand and afterwards, then you know whether the file has been deleted.
User avatar
Chunjee
Posts: 1501
Joined: 18 Apr 2014, 19:05
Contact:

Re: How to know if filedelete deleted a file?

09 Jun 2021, 11:46

ErrorLevel is set to the number of files that failed to be deleted (if any) or 0 otherwise
So

Code: Select all

if (ErrorLevel == 0) {
	; log success
}
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: How to know if filedelete deleted a file?

09 Jun 2021, 11:50

Good point. The documentation is confusing about this, but my understanding is the ErrorLevel will still reflect the number of failed deletions. If the mask matches no files, then there are no failures.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: pond_pop and 322 guests