Get filename from full or relative path knowing that this parameter is not a batch parameter

When a file, along with a relative path or full path ..., is given as a package parameter, I know how to expand% 1 to get the filename

    %~n1 

      

It's pretty simple!

However, I want to get the name of the file from its relative / full path, which is processed inside the package.

Please see my code. I would like to expand %% x (which is a relative path in my case) to only account for its filename. Do you have any ideas please? Thanks to

 @echo off
 SETLOCAL EnableDelayedExpansion
 set currDir=%CD%
 for /f "tokens=*" %%x in (Lists.out) do (
 echo %%x
 set filetxt=%%x)

      

Here is an example "Lists.out" file with some different files embedded in relative paths. "Lists.out" can be made from

   Temp\my file1_X
   Temp\my file2_X
   ...............

      

-1


source to share


1 answer


...
 echo %%~nx
 set filetxt=%%~nx)

      

should cure your problem.



or use ~nxx

if you want an extension too.

0


source







All Articles