I have a problem, one whose solution I stumbled onto a couple years ago but - alas - my storage recently crashed and I lost the batch file!
We start w/ this awkward file name:
The following BAT utility cleverly strips everything in front of the 'A' (first 23 chars.):
@echo off for %%i in (*.dat) do (set fName=%%i) & call :rename goto :eof :rename :: Crops the 1st 23 characters of fName ('rank(all)_so2_1hr_conc_'): ren %fName% %fName:~23% goto :eof
Great! This renders:
Now I need to convert this to:
Notice '...h10' needs to be '...h100'. Note that, while in this example, the part preceding the '.' is 'A_2p5h10', it could be any 8-character string (so we'll need a wildcard or something).
Can you please suggest a routine that will add the ' 0 ' in the middle of the file name (preceding the '.')? There are hundreds of file names in the directory that need to have this conversion.
As I recall, the critical command (I believe used REN) that used to do this was extremely simple (contained one of more %, as I recall).
You can use this script:
@echo off for %%i in (*.dat) do (set fName=%%i) & call :rename goto :eof :rename :: Rename the file by discarding first 23 chars, and last 7 and adding H100.plt at the end ren %fName% %fName:~23,-7%H100.plt goto :eof
Thanks to Tommy for this tip on the forum.
- BAT command to insert a char. in a file name
- BAT command to insert a char. in a file name ✓ - Forum - Programming
- How to prevent command prompt from closing after running batch file - How-To - Operating Systems
- In ftp which category of commands is used to store and retrieve files - Articles
- Command not working in .bat file ✓ - Forum - Programming
- What are the steps to insert photo in word for resume - How-To - Word