Reputation: 2367
I have a set of files in a directory like below:
File-MyFile.txt File-AnotherFile.txt File-ThirdFile.txt
I want to rename all files like below:
MyFile.txt AnotherFile.txt ThirdFile.txt
How can I use a for
loop to do that?
Upvotes: 1
Views: 2508
Reputation: 2053
Chris shows the best way to do it. I think this might come close to what you asked for, though I didn't test it:
@echo off
for /f %%a IN ('dir /b *.txt') do call :dorename %%a
goto :eof
:dorename
set oldfile=%1
set newfile=%oldfile:File-=%
rename %oldfile% %newfile%
Upvotes: 3