Reputation: 127
My file names pattern is a_AA-A.txt or a_11-1.txt. I need to remove "a_" from the file name.
Is it possible to edit / remove "a_" from file name through batch commands.
I am using windows 7
Thanks in advance!
Upvotes: 0
Views: 601
Reputation: 14325
If you need to simply remove the first two characters
@echo off
setlocal enabledelayedexpansion
for /f %%A in ('dir /b a_*.txt') do (
set old_filename=%%~A
set new_filename=!old_filename:~2!
rename !old_filename! !new_filename!
)
If you want to remove the characters a_
@echo off
setlocal enabledelayedexpansion
for /f %%A in ('dir /b a_*.txt') do (
set old_filename=%%~A
set new_filename=!old_filename:a_=!
rename !old_filename! !new_filename!
)
Upvotes: 1
Reputation: 4692
not sure you can do this with batch... but you can do it with vbscript for sure...
and you can call it from your batchjob
Upvotes: 0