ExifTool Forum

ExifTool => Newbies => Topic started by: AlanX on March 22, 2020, 10:30:49 AM

Title: Simple file renaming with sequence number
Post by: AlanX on March 22, 2020, 10:30:49 AM
I'm almost embarrassed to ask this, but most examples I've found are for something more complicated than I'm trying to do!
I have a folder of images with filenames in various formats that I wish to replace with a fixed string (same for all images) followed by a numeric sequence. So whatever the original filename, it renames to <my fixed string>-1.jpg, <my fixed string>-2.jpg, and so on, perhaps to a maximum of 100 images. The option to drop these renamed copies into a different folder would be useful.
Many thanks.
Title: Re: Simple file renaming with sequence number
Post by: Phil Harvey on March 22, 2020, 10:34:09 AM
Maybe something like this?:

exiftool -filename="my fixed string-%.nc.%e" -directory="different folder" -ext jpg DIR

- Phil
Title: Re: Simple file renaming with sequence number
Post by: StarGeek on March 22, 2020, 11:07:29 AM
Quote from: AlanX on March 22, 2020, 10:30:49 AMperhaps to a maximum of 100 images. The option to drop these renamed copies into a different folder would be useful.

I haven't tried it, but to limit it to a max of 100 images, I'd think you could add
-if "$FileSequence<100"
Title: Re: Simple file renaming with sequence number
Post by: AlanX on March 22, 2020, 12:40:46 PM
Thanks, Phil, but not quite working for me.
I'm running:

C:\ExifTool\exiftool -filename="my fixed string-%.nc.%e" -directory="different folder" -ext jpg F:\exiftest\testgallery

The testgallery folder contains 5 JPGs. When I run the script, the "different directory" folder is created, and one image gets moved there (not copied), and is renamed 'my fixed string-e' without extension (not sure where the 'e' is coming from!). If I add '.jpg', the file becomes viewable again. I was hoping for all 5 images to be copied to the new folder, and renamed 'my fixed string-1.jpg, 'my fixed string-2.jpg, ... 'my fixed string-5.jpg.
Appreciate your help as always.
Title: Re: Simple file renaming with sequence number
Post by: StarGeek on March 22, 2020, 01:23:25 PM
Quote from: AlanX on March 22, 2020, 12:40:46 PM
is renamed 'my fixed string-e' without extension (not sure where the 'e' is coming from!).

I'm guessing this would be FAQ #27 (https://exiftool.org/faq.html#Q27).

Quote from: AlanX on March 22, 2020, 12:40:46 PMI was hoping for all 5 images to be copied to the new folder,

To be honest, your original post seems to me to indicate you wanted the files moved, not copied, which is what Phil's command does. 

I'm not sure if it's possible to rename a file and additionally make a new copy of that file with the new name in a different directory.  The -o (Outfile) option (https://exiftool.org/exiftool_pod.html#o-OUTFILE-or-FMT--out) can be used to make a copy in another directory with a new name, but that doesn't rename the original. 

I think the best bet would be to run Phil's command above, then copy the renamed files back into the original directory.  Phil will probably correct me if there's another way.
Title: Re: Simple file renaming with sequence number
Post by: AlanX on March 22, 2020, 01:52:09 PM
Many thanks - FAC#27 had the answer.
I can handle the move versus copy, even if I end up doing it manually.
Title: Re: Simple file renaming with sequence number
Post by: Phil Harvey on March 23, 2020, 07:30:30 AM
Quote from: StarGeek on March 22, 2020, 01:23:25 PM
I'm not sure if it's possible to rename a file and additionally make a new copy of that file with the new name in a different directory.

...not in a single command.

QuoteI think the best bet would be to run Phil's command above, then copy the renamed files back into the original directory.  Phil will probably correct me if there's another way.

I don't see another way.

- Phil