ExifTool Forum

ExifTool => Newbies => Topic started by: johnicepick on August 22, 2024, 01:23:34 PM

Title: Move files if older than x minutes
Post by: johnicepick on August 22, 2024, 01:23:34 PM
Hello everyone,

I googled this question with different variations, but I did not find the answer I'm looking for.


I'd like to move files into another folder when they are older than x minutes. Preferably based on "Last Modified" and not "DateCreated".
So whenever a photo/file has "Last Modified" timestamp which is older than 3 minutes I want to move it into a different folder.

The code would run as a batch file every few seconds.

I did look into the docs, but I did not find any similar yet?
(For google and for others who may search for the same issue: "Move files if older than x days" "Move files to subfolder if older than x hours" "Copy files if older than x years")

By the way: Thank you for this awesome forum, the time the community invests in answering each of those questions.... true heroes!
Title: Re: Move files if older than x minutes
Post by: StarGeek on August 22, 2024, 01:35:48 PM
The first step is to figure out what the "Last Modified" and "DateCreated" tags actually are.  This would be FAQ #3 (https://exiftool.org/faq.html#Q3).

I'm going to assume that "Last Modified" is going to be the FileModifyDate.

Try this
exiftool -if "$FileModifyDate# ge ${Now#;ShiftTime('-0:3:0')}" -Directory=/dir/to/move/to/ /path/to/files/
Title: Re: Move files if older than x minutes
Post by: johnicepick on August 23, 2024, 12:57:09 PM
Hello StarGeek,
Hello everyone,

Thank you very much for your answer.
You're correct with FileModifyDate - that's what I need.

I did notice that your code is not directly working. But instead of whining I searched for a solution. Your ge (greater?) needs to be a le (lesser?) instead, thanks to google & your forum I could figure that one out. I thought at first that the timezones might be in the way, or that the time connotation is missing the day...
Interesting feature: an unaltered JPG created by a photocamera gets directly moved and a edited JPG (Lightroom) will never get moved with the code from above  ???


So exchanging ge with le works like a charm.


So the full line looks like:
exiftool -if "$FileModifyDate# le ${Now#;ShiftTime('-0:3:0')}" -Directory=/dir/to/move/to/ /path/to/files/

This might of interest for other ppl finding my post:
The code above will not move a file if the target directory has a file with an identical name. The following code will rename the file (by adding +1,2,3... at the end of the file).
exiftool -if "$FileModifyDate# le ${Now#;ShiftTime('-0:3:0')}" -filename=C:\targetdirectory\subfolder\%%f%%c.%%e C:\originalfolder\subfolder

Thank you very much StarGeek :)
Title: Re: Move files if older than x minutes
Post by: StarGeek on August 23, 2024, 01:18:04 PM
Ooops, sorry. I misread it and thought you meant more recent than 3 minutes. Glad you figured it out.