I would like to read the name of all *.kla files from a directory (C:\TSData\Klarf) and change their names and then move them to a new directory (E:\MESSDAT\DATEN\Klatencor\Klarf).
For file name renaming, in each .kla file, there are two variables that i need to get their values: (for example) LotID "N_123"; Slot 1; and combine these variables like this: LotID_Slot.kla to make a new name.
I wrote this code but after moving a .kla file to a new directory its name is not changed correctly. The file name becomes _. kla. i think these variables (LotID,SLOT) are null. what shoud i do?
@echo off
setlocal enableextensions disabledelayedexpansion
set "LotID="
set "Slot="
for /f %%l in ('dir /b C:\TSData\Klarf\*.kla') do (
for /R C:\TSData\Klarf\ %%i in (*.*) do echo %%~nxi
for /f "usebackq tokens=1,*" %%a in (
"C:\TSData\Klarf\%%l"
) do for %%c in (%%b) do set "%%a=%%~c"
move /-y "C:\TSData\Klarf\%%l" "E:\MESSDAT\DATEN\Klatencor\Klarf"
ren "E:\MESSDAT\DATEN\Klatencor\Klarf\%%l" "%LotID%_%Slot%.kla"
echo %%l moved!
)
Consider that in C:\TSData\Klarf\ there is a file name= 1.kla after execution of path file this file will be renamed to k1_1.kla (because for this file we have LotID=k1, Slot=1) and will move to new directory called E:\MESSDAT\DATEN\Klatencor\Klarf\ with its new name (k1_1.kla).
I dont know why this following For works well alone for a clear .kla file.
:: Finding LotID, Slot in each .kla file
for /R C:\TSData\Klarf\ %%i in (*.*) do echo %%~nxi
for /f "usebackq tokens=1,*" %%a in (
"C:\TSData\Klarf\K.kla"
) do for %%c in (%%b) do set "%%a=%%~c"
move /-y "C:\TSData\Klarf\k.kla" "E:\MESSDAT\DATEN\Klatencor\Klarf"
ren E:\MESSDAT\DATEN\Klatencor\Klarf\k.kla "%LotID%_%Slot%.kla"
Thanks a lot for ur help!