Rename a text file using batch or VBS
I need to rename a text file using either a batch file or a vbscript. The format of the txt file is received as A353XXXXXXXX.txt and I need it to be renamed to simply A353.txt. The X's are never the same but the A353 is always the same. All sc开发者_JAVA百科ripts that I have tried are not executing properly. I need it to rename the file by the first four characters of the file name. It seems easy but it is giving me fits for some reason.
Just rename using:
ren A353*.txt A353.txt
Got it:
Set var=A353xxxxxxxx.txt
ECHO %var%
Set var=%var:~0,4%.txt
ECHO %var%
PAUSE
move "A353xxxxxxxx.txt" "%var%"
We can iterate this over many files with a for loop as well.
精彩评论