I want to read the name of a file in windows batch programming. I am trying by using different methods but failed please help.
Scenario has been given below.
I have different files in a folder but the length for filename is same for all files. E.g.
1000342578_30062011.PDF
1000342329_30062011.PDF
And I just want to save the part after _ and before .PDF (e.g. 30062011) part in a variable.
Below are just tries but I am not able to get through.
@echo off
echo.Date : %date%
echo.Year : %date:~10,4%
dir /s /b C:\Users\zeeshando\Desktop\*.txt
for %%x in (c:\temp\*.xls) do echo %%x
lfnfor off
for %%x in (*.*) do echo %%x > filelist.txt
PAUSE
for %i in (C:\Users\zeeshando\Desktop) do
echo %~ni
PAUSE
UPDATE
My current code, based on @Alex K.'s answer:
@setlocal enabledelayedexpansion
for %%x in (C:\Hi\*.*) do (
set fn=%%x
set fn=!fn:~22,8!
echo !fn!
call:handler
)
goto:eof
:handler
echo !fn!
copy C:\Hi\*.* E:\!fn!
goto:eof
PAUSE
But it is not copying the files. Please check the above code.