I have written batch file to extract last 8 character of multiple files in folder. But that batch file not giving desired result. My folder consist of below mentioned filenames sub_rachit_01.pdf and sub_kapoor_02.pdf. I want to extract rachit_01 and kapoor_02 as variable from folder. Batch File is shred below:
@echo off
set /p location=Please enter location of .pdf files:
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%a in ('dir /b %location%\*.pdf') do (
set filename=%%~na
set file=%filename:~-8%
echo %file%
)
pause
%characters on your last two commands inside the parentheses to!characters.