1.

Solve : Capture the file name as a parameter?

Answer»

Thanks
but would you mind explain the logic to me ?
SURE, no problem.

Quote

:: This line turns echo off, which means only the output of commands is displayed.
@echo off

:: As below
for /f "usebackq delims=" %%I in (`dir/b c:\*.txt`) do (
set name=%%~nI
)

:: Sets the variable %m% to the fifth and SIXTH characters in %name%, offset 4 is same as 5th character, 2 after that inclusive.
set m=%name:~4,2%

:: Echos the %m% variable
echo %m%

pause


FOR STATEMENT DESCRIPTION:
For /f "usebackq delims=" means that for will use backwards quotes, just a habit ` instead of '.

The delims part means that the output should be treated a a whole phrase and not split into sections when a character is reached, not really necessary either.

"%%I" defines a temporary variable to use in the for statement body.

"in (`dir/b c:\a\*.txt`) do" For each line that the command "dir/b c:\*.txt" returns the following will be performed.

"(" indicates start of body.

"set name=%%~nI" Sets the variable %name% with the file name only (~N) in the variable %%I, ie no extension.

")" END body



NOTE: You didn't mention the file was in a folder called "a".


Discussion

No Comment Found