Simple file renaming with sequence number

Started by AlanX, March 22, 2020, 10:30:49 AM

Previous topic - Next topic

AlanX

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.

Phil Harvey

Maybe something like this?:

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

- 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: 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"
* 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).

AlanX

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.

StarGeek

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.

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 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.
* 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).

AlanX

Many thanks - FAC#27 had the answer.
I can handle the move versus copy, even if I end up doing it manually.

Phil Harvey

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
...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 ($).