Move/copy files based on creation date

Hi there!
I’m new to this and can not find a way to move or copy files from one folder to another based on creation or modification date of the files.


Do you want to trigger this manually from a bunch of files you’ve selected, or automatically have the system do it every so often?

Thank for a really fast answer!

I want to trigger this manually for the moment. I want KM to look into a bunch o folders and nested folder and copy the files to one specific folder in another volume. But just files created or modified within the last two weeks. You can compare it with a kind of backup.

If there is a way to trigger this on a specific day it would be nice as well.

Do you want the files to be put altogether into one folder, or to you want them to be still nested in subfolders like they originally were?

I believe the following macro will do what you need. (That said, Automator (free) or Hazel (worth the money) might be a better option for this.)

You'll need to change the hardcoded directories to the directory you're watching and the directory you're copying the files too. This puts all the files in one folder. If you need it different, per my question above, that shouldn't be too hard to adjust.

Basically, it

  • looks at all the files in the given folder
  • sets the duration you care about to 2 weeks in seconds (1209600)
  • gets the last modification date
  • calculates the time from the last modification to now
  • If the time since the last modification is less than the duration you picked, and the path object is a file (to avoid applying this to folders then
  • move that path to your chosen directory.

There might be a better way to do the date math, but I don't know what it is.

Jonas_Bohlin test macro.kmmacros (4.7 KB)



I’m trying to use this to do a similar thing. and the above works if the output is sent to one folder. However what do I have to change so that the files are copied to the new location but they are still nested in subfolders like they originally were.

Thought adding t%variable%path% to the end of cop to string would work but didn’t . New to this tool, just bought it

Also the file structure does not exist in the target so will need to create the folders

Thanks in advance

Hey Brad,

Creating a non-extant directory structure is not so very simple with KM by itself. KM will not copy to a location that doesn’t exist.

You can use the Unix executable mkdir with the ‘-p’ switch to make a directory and create the tree as necessary, but then you have to copy the file.

It might be simpler for you to do the actual copy part with the Unix executable rsync.

rsync -avRX '/Users/chris/test_directory/./KM_MOVE_TEST/KM_URL-File_Test.txt' ~/Desktop/tmp/

“/./” is inserted at the point where I want to prune the directory tree.


Look in the man page for this paragraph:

“It is also possible to limit the amount of path information that
is sent as implied directories for each path you specify. With
a modern rsync on the sending side (beginning with 2.6.7), you
can insert a dot and a slash into the source path, like this:”

Rsync will build your directory structure for you as well as copy the file.

Best Regards,