How to operate on a range of files

Started by Rita428, April 22, 2014, 05:14:44 PM

Previous topic - Next topic

Rita428

I can't seem to find an answer to this question (might be trivial, sorry that I'm a newbie):
Assume I have a directory with hundreds of files. The files have names with increasing ordered numbers (for eample: image_001.jpg, image_002.jpg, image_003.jpg, ... image_999.jpg).
I would like to change (write) a certain tag to a sub-range of these files (for example, "exiftool Orientation#=6 'image_220.jpg to image_229.jpg' "
(I've just invented this syntax, to explain what I need). What's the right way to do this?

Many thanks in advance - Rita

(Running exiftool 9.56 on Ubuntu 12.4.04 "precise")

Alan Clifford

I'd use:

exiftool -Orientation#=6 image_22[0-9].jpg

assuming you are using the bash shell.

Edit.  But you can drag-and-drop files onto exiftool.  I have never done this so I won't even attempt to explain!

Rita428

Thank you, Alan.
1. This:
exiftool -Orientation#=6 image_22[0-9].jpg
seems to be working for the last digit only. i.e. this doesn't work:
exiftool -Orientation#=6 image_2[23-31].jpg
is there a way to do this? (for ranges GT 10)?

2. "But you can drag-and-drop files onto exiftool" - can you do this in Linux? I thought on Linux there is only command line interface?

Many TIA

RIta

Phil Harvey

Hi Rita,

I don't know how to do ranges, but you can drag and drop files onto most terminal windows, so just type "exiftool", SPACE, then drop your files and press RETURN.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Rita428 on April 23, 2014, 03:43:45 PM

exiftool -Orientation#=6 image_2[23-31].jpg
is there a way to do this? (for ranges GT 10)?

Alan was using regular expressions to get the files you want.  The Range expression doesn't work like that.  What you want would be more like this:
exiftool -Orientation#=6 image_2(2[3-9]|3[0-1).jpg

Maybe...  I don't know enough about bash shell to know if that will work, but that's the expression that will match 23-31.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

That definitely won't work because "|" is a pipe operator.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alan Clifford

Quote from: Rita428 on April 23, 2014, 03:43:45 PM
seems to be working for the last digit only. i.e. this doesn't work:
exiftool -Orientation#=6 image_2[23-31].jpg
is there a way to do this? (for ranges GT 10)?


To keep it simple, I'd use this:

exiftool -Orientation#=6 image_22[3-9].jpg  image_23[0-1].jpg

If you wanted all the 220's and all the 230's, you could use two sets of square bracket but that would cover more than your specific example.  But i've included it as another example:

exiftool -Orientation#=6 image_2[23][0-9].jpg

It might be wise to first do something like
exiftool -Orientation# image_2[23][0-9].jpg
to check you've got the regular expression right without changing anything!

I'm not sure if exiftool has a trial run flag.  If not, Phil, that's a suggestion.

Phil Harvey

Unfortunately, implementing a trial run flag is far more difficult than one might imagine because the processing of subsequent files may be affected by earlier output.  So one can not easily guarantee that the trial run results will be accurate.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alan Clifford

Quote from: Phil Harvey on April 24, 2014, 07:17:50 AM
That definitely won't work because "|" is a pipe operator.

- Phil

I've been looking at bash.  With extended globbing, this sort of syntax is used:

alan@egremont:temp$ shopt -s extglob
alan@egremont:temp$ exiftool -orientation# image_2*(2[3-9]|3[0-1]).jpg
======== image_223.jpg
======== image_224.jpg
======== image_225.jpg
======== image_226.jpg
======== image_227.jpg
======== image_228.jpg
======== image_229.jpg
======== image_230.jpg
======== image_231.jpg
    9 image files read


The OP might find drag-and-drop to be a better solution.

But I've learned something today that will be useful.

Phil Harvey

I've learned something too.  Thanks.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).