Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace part of a file name with another name in batch processing

I have been trying to replace a part of some file names in a directory to new names. I have found many examples regarding this replacement using REN command with a for loop.

Example: if I want to replace test001 to test003, I can replace using REN.

But what,if I take 001 and 003 as user input through set \p command and I want the output to be test003, for the input test001.

I have the following files in my folder:

Test001.txt
user001.txt
fjkdjdl001.txt

I want to convert them to

Test0003.txt
user003.txt
and so on.

But 001,003 are user inputted.

How for+ren act with user inputted characters.Please help me.

like image 746
raghavendra Avatar asked Sep 06 '25 02:09

raghavendra


1 Answers

Often times you do need a small batch script to execute some seemingly simple rename operations. However, you only need the REN command in this case.

ren *001.txt *03.txt

See How does the Windows RENAME command interpret wildcards? for an explanation as to why this works.

like image 130
dbenham Avatar answered Sep 07 '25 23:09

dbenham