ANONYMOUS wrote:
> In summary, my program stealthily copies and deletes any empty directories before it finishes, which does produce desired output of not syncing empty directories. I'm just wondering if this method is an acceptable method or if I've done it in a convoluted way.
Whether this approach is described as working silently, stealthily, or convoluted, you'd surely have to agree that it's inelegant? I can't think of many (any?) tasks in computing where we perform an activity, and then undo it later on to achieve the desired result. If this involved only manipulation of data in memory, then it'd be far more acceptable, but we've emphasised that accessing the file-system, potentially on a slow physical device, is best avoided if possible.
If you think about what it means for a directory to be 'empty', then you really should be able to write a short function, fewer than 10 lines, to determine if a directory is empty. But if that function requires many trips to the file-system then it, too, is not a good approach.
> My reasoning for this, is that when pairing -n with -r, my program can only work recursively if it can see the directories to be sync'd in disk, and wouldn't work if I didn't silently copy empty directories then delete them after recursion.
I'm afraid that I'm unable to follow this reasoning - the -r option indicates how top-level directories (and possibly their subdirectories) should be traversed in search of files; the -n option indicates if we should actually copy the files if there is the need. There's nothing in that combination about directories being empty or not.