Copie automatique dans un dossier daté

J’ai actuellement un raccourci qui copie un fichier vers un autre dossier. Je voudrais le modifier pour que la copie soit enregistrée dans le dossier source, à l’intérieur d’un sous-dossier créé automatiquement et nommé avec la date du jour. Si ce dossier existe déjà, il ne faut pas le recréer ni le supprimer, mais simplement y ajouter le fichier.

Copy le fichier "A JETER LORS DE LA GRAVURE" dans le meme repertoire.kmmacros (2.9 KB)

(Thanks, Google Translate!)

You need the current date. You can get that with the %ICUDateTime% Token in the format you want -- I suggest YYYY-MM-DD, the output today would be 2026-06-30, so that sorting folders by name will also sort them by their date:

%ICUDateTime%yyyy-MM-dd%

You need to make a folder -- that's the "New Folder" Action. You don't need to "Create Intermediates" as you are making the new folder inside one that already exists. And you know where to create it -- the "parent path" of selected file's folder, like you used in your uploaded macro.

The "New Folder" Action fails gracefully, the macro continuing, if a folder with that name already exists -- so you don't need to check first, just try and create the folder every time.

You then copy the selected file to the dated folder.

Putting that all together:

Copy Selected File to Today's-Date Folder.kmmacros (2.9 KB)

Before anyone leaps in with "You don't need those first two Actions, Nige! Evaluate the Tokens in the "Split" and "Create Folder" Actions." -- this macro is deliberately "defensive", limiting the chance of a mismatched date if triggered bang on midnight or the Finder selection changing during execution.

Hardly necessary here, but I'm trying to get better at doing things "properly" :wink:

My attempt was similar to @Nige_S’s (but alternative solutions might include shell commands or other scripting).

Copy into dated subfolder..kmmacros (5.5 KB)

Notes:

  • If a file (as opposed to a folder) exists at the intended destination path, the macro will explain that and then cancel itself.
  • The macro will fail if more than one file has been selected for the move. An improved version could make use of the For each path in Finder selection.
1 Like

Colour me surprised -- I couldn't understand how yours worked because you aren't providing a destination file name and, according to the Wiki:

Copy: copies a file or folder. You must specify a name and location for the copy.

...but it appears that if a name isn't provided it uses the current one. Neat!

I’ve always just taken it for granted that the logic of copying and moving in KM would operate with the same logic as copying and moving in Unix. :slight_smile:

1 Like

You must supply the full file path of the file you are copying (name and location), and the destination, which is either a full file path to an existing directory with no matching file name in it (name is preserved), or the full path to a non-existent file in an existing directory (name provided by the destination path).