Get file name by CMD
Solution 1:
I need from this Full Path, only the File Name.
for /f "delims=" %%a in ('dir /s /b sqlncli*.msi') do set "name=%%a"
Use the %~n
operator:
for /f "delims=" %%a in ('dir /s /b sqlncli*.msi') do set "name=%%~na"
If you want the filename and the extension, use the %~nx
operator:
for /f "delims=" %%a in ('dir /s /b sqlncli*.msi') do set "name=%%~nxa"
%~n1
Expand%1
to a file Name without file extension or path -MyFile
or if only a path is present, with no trailing backslash, the last folder in that path.
%~x1
Expand%1
to a file eXtension only -.txt
Source parameters - A command line argument (or parameter) is any value passed into a batch script.
Further Reading
- An A-Z Index of the Windows CMD command line | SS64.com
- Windows CMD Commands (categorized) - Windows CMD - SS64.com
- parameters - A command line argument (or parameter) is any value passed into a batch script.