Running batch file only on images recently modified

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
harryhermit
Posts: 4
Joined: 2018-09-24T10:23:26-07:00
Authentication code: 1152

Running batch file only on images recently modified

Post by harryhermit »

Hi,

I run a batch script to modify images in folders and subfolders in windows. It works great, but it runs imagemagick for every single image in the folders. Is there a way to limit the files that are modified to a time period eg. a week from date modified?

Thanks
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Running batch file only on images recently modified

Post by Bonzo »

I would suggest you create a script to loop through all the files you want to modify and only send the one to IM that meet the criterial.

Just remember if you go by time span you will have to make sure the ones you ran in the previous run are older; otherwise they will be changed again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Running batch file only on images recently modified

Post by fmw42 »

You would have to use your OS to test the modified date in your loop and do an if test on the date range. If it passes then process. If it does not pass, then skip the file via you looping mechanism (such as continue in unix)

Please, always provide your IM version and platform when asking questions, since syntax may differ.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Running batch file only on images recently modified

Post by GeeMack »

harryhermit wrote: 2018-10-13T23:24:42-07:00I run a batch script to modify images in folders and subfolders in windows. It works great, but it runs imagemagick for every single image in the folders. Is there a way to limit the files that are modified to a time period eg. a week from date modified?
As the others have mentioned, you'll probably do best to use some system utility to check or sort your files according to the modified times/dates. If you're using Windows Vista or newer, try this at the command line to learn about the "forfiles" command...

Code: Select all

forfiles /?
That can find files that meet certain criteria, then it can echo those files' names to a list for IM to use, or it can run an IM command on each qualifying file.
harryhermit
Posts: 4
Joined: 2018-09-24T10:23:26-07:00
Authentication code: 1152

Re: Running batch file only on images recently modified

Post by harryhermit »

The forfiles command looks promising, but I'm having issues with it bringing up the correct products with my criteria. What's the correct command to bring products that have been modified within the past 7 days? I tried this command, but it seems to bring products that are older than 7 days ago:

forfiles /D -7

Using

forfiles /D +7 doesn't bring up any results

I can get the last 7 days by setting the command to bring files newer than a date 7 days from the current date, but I'd have to manually set the date each time. That wouldn't be the automatic solution I am seeking

forfiles /D +10/08/18

Any help would be appreciated
Post Reply