Im trying to build a batch file.
I have 30 csv files in a folder
My intention is
- Get each file name (Example is 097_021216_192332.csv)
- Extract the first 3 digits
- Compare it with a lookup table ( lookup1.bat) against which i have marked another string
EG: lookup1.bat
@echo 107=B_05-
@echo 097=B_06-
@echo 149=B_07-
@echo 109=B_08-
@echo 101=B_09-
@echo 105=B_10-
@echo 098=B_11-
So here i will get "B_06-"
- Modify the file name with this "B_06-" prefix and rename the file
Here is my code , i have only basic ideas about looping and im struggling a lot.Thanks for any help.
@echo on
setlocal enabledelayedexpansion
for %%a in ("*.csv") do (
set FileName=%%~na
goto:stepa
goto:eof
)
:stepa
for /f "tokens=1 delims=_" %%a in ("%FileName%") do (
set A=%%a
echo %A%
)
@SET MN=%A%
@FOR /F "tokens=1,2 delims==" %%i IN ('lookup1.bat') DO @IF %%i EQU %MN% SET MW=%%j
@ECHO The board number corresponding to %MN% is %MW%.
set "str=%MW%%FileName%"
echo "%str%"
Ren "!FileName!" "!str!"
:eof