How to test whether a specific file exists

Hey Victor,

Sure it does. I test every macro I post.

(Tested with Keyboard Maestro 7.0.4d2 on OSX 10.11.3.)

The pattern is case-sensitive though. To make it case insensitive:

(?i)^file

In your first macro you're searching to see if the entire path contains “file”.

That is potentially VERY dangerous.

Suppose one folder-name in the path is “file” or contains “file”:

~/yourUser/To Be Filed/Jpeg Folder/

You could wipe out a bunch of files you didn't intend to delete.

You could use a regular expression to safely test against the full file-path, but it's less complicated (and therefore safer) to test the file-name instead.

You have two tests:

A) ^file(.+)\.wpd$
B) fileName contains “file.wpd”

This is not wrong, but it's more complicated than necessary. Also “contains” is a far cry from “starts with”.

By changing your regular expression slightly you can narrow that down to 1 test:

^file(.*)\.wpd$

The asterisk indicates zero or more instead of the plus sign's 1 or more.

My original pattern (^file) should work. If it is in fact NOT working then something is very strange.

However – ^file(.*)\.wpd$ is a much safer pattern to use if you want to restrict delete files to WordPerfect documents.

-Chris

1 Like