Computer Hope

Microsoft => Microsoft DOS => Topic started by: colombo on January 18, 2017, 05:00:31 AM

Title: Batch/Multi rename only files with a specific range
Post by: colombo on January 18, 2017, 05:00:31 AM
Hello, i hope someone can help me with this.

i have a bunch of consecutive  files
sometimes 10 files sometimes 22 files - it doesn't matter how much
 e.g
001.xxx
002.xxx
003.xxx
004.xxx
...
i want to write a Bach file that will duplicate all files except the first and last and will rename them Consecutively to the last file
so for the e.g above it will look like this:

001.xxx
002.xxx
003.xxx
004.xxx
 005.xxx
 006.xxx

file 003.xxx was duplicated+renamed to 005.xxx
and file 002.xxx was duplicated+renamed to 006.xxx
first file 001.xxx and last files  in this case it was 004.xxx didn't play in this command
 i did wrote this command:

copy 003.xxx 005.xxx
copy 002.xxx 006.xxx

but this command is only working if i am starting with 4 files
the problem is the amount of files i am starting with is different each time
i need your help to write something that will apply only on the 'between' files no matter how much of them

Thank you
Title: Re: Batch/Multi rename only files with a specific range
Post by: Squashman on January 18, 2017, 07:20:25 AM
So use a FOR /F command to parse the output of the DIR command.  Use the options with the DIR command to sort the file alphabetically and then in reverse.