Best Practice for Detecting if a Folder is Busy?

Hey Folks,

Is there a new/recent best practice for determining if a file/folder copy/move is complete before continuing operations on the target folder?

I seem to remember a topic discussing this a few years ago can’t seem to find it…


Just yesterday (and still today) I am working on something similar for my tool Find Any File:

The task of tracking files that get replaced or rewritten, optionally using a temporary file/folder that gets swapped in in the end.

In these cases, when I track the original file by its ID (via NSURL’s fileReferenceURL), I find that it either gets renamed and then deleted, or gets deleted, and then I need to wait for the new file/folder to appear at the same path.

The solution is to rely on FSEvents. It’ll send you a change to the enclosing folder twice, once when the original gets renamed or deleted, and once the new one appears there.

So, you have to know the paths you’re tracking, and then wait for the FSEvents, checking if the path is back, but with a different file ID (i.e. fileReferenceURL).

The problem for you might be that handling FSEvents callbacks may be difficult with AppleScript. Maybe there’s a library for it?

1 Like