Rename files in numbered sequence from the command line

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

Post Reply
Trenthee
Posts: 6
Joined: Wed Aug 12, 2015 11:29 am

Rename files in numbered sequence from the command line

Post by Trenthee »

Is it possible to rename multiple files with different image formats in numbered sequence from the command line?

I use Linux Mint. The following command will rename all files in a folder, regardless of extension:

Code: Select all

c=0; for i in *; do let c++; mv "$i" "gg_$(printf "%03d" $c)${i#"${i%.*}"}"; done
But I would like to use NConvert for renaming files, if possible, and regardless of extension.

I've read this thread and some others, but haven't found a solution and don't know if it's possible.

I'd like the files to be renamed using the following naming convention:

gg001
gg002
gg003
cday
XnThusiast
Posts: 3976
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Rename files in numbered sequence from the command line

Post by cday »

Trenthee wrote: Wed Oct 03, 2018 1:01 pm Is it possible to rename multiple files with different image formats in numbered sequence from the command line?
Maybe...

Have you created a copy of the NConvert help file?

The relevant code is:

Code: Select all

-o filename       : Output filename
              Use # to specify position of numeric enumerator
For reference other options are:

Code: Select all

-o filename       
              Use % to specify source filename
              Use $ to specify full source pathname
              Use $$ to specify source folder name
              Use $EXIF:DateModified[date format] to specify EXIF date modified
              Use $EXIF:DateTaken[date format] to specify EXIF date taken

Running NConvert in Windows, the follow basic code [tested in a batch file and using relative addressing] seems to produce the basic result you need:

Code: Select all

nconvert -o gg### Test\*.*
Whether code based on the above produces the result you need will depend in part on the sequence in which your source files are read, considering that you have multiple file extensions and the numeric sort order when they are read: command line software run in Windows reads files with unpadded file numbers 1, 2,10, 11 in the non-numeric sequence 1,10, 11, 2... :(

Note that there seems to be a bug in NConvert 7.20 in that the output file number count in my test setup starts at 003 rather than 001 -- NConvert 6.93 produces the expected result.

Earlier versions of XnView software can be downloaded here: Old versions

[Edited]
Post Reply