Windows – Is it possible to change a filename prefix using the rename command with wildcards

command linerenamewindows

I have read as much of How does the Windows RENAME command interpret wildcards as I can understand, and still cannot decide if there is some wildcard combination you can use to make RENAME do this:

Old file names: abc001.txt, abc002.txt, abc003.txt, ... etc
New file names: demo_001.txt, demo_002.txt, demo_003.txt, ... etc
or: x001.txt, x002.txt, x003.txt, ... etc
or: file01.txt, file02.txt, file03.txt, ... etc

What I do know is that rename abc*.txt xyz*.txt will change all abc prefixes to xyz, but only because abc and xyz are of identical length. Is there a simple rename command which will cope with either a shorter or longer prefix… or do you have to use a batch process to carry out such renames?

Best Answer

The answer is No, you cannot change the length of a file name prefix like you want using just the RENAME command with wildcards. It will require some amount of more complex scripting, or else a non-standard 3rd party tool.

If you read the rules carefully, you will see that the wildcards in the source mask have no bearing in the rename result - they only filter which files are renamed. The non-wildcard prefix characters in the target mask substitute one for one with the characters in the original name.

Related Question