-1

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

    %~n1 

It's quite easy!

Nevertheless, I want to get the name of file from its relative/full path which is right handled inside the batch.

Please look at my code. I'd like to expand %%x (which is a relative path in my case) to take account only its file name. Please do you have any idea? Thanks

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

Here's an example "Lists.out" file with some different files built-in relative paths. "Lists.out" can be made of

   Temp\my file1_X
   Temp\my file2_X
   ...............
new
  • 1,109
  • 5
  • 21
  • 30
  • Instead of `"tokens=*"` you should use `"delims="`. Then if you want to expand `%%x` to a full drive:path\filename.ext use `%%~fx`. See the last couple of pages of `help for` for more information. – rojo Apr 18 '13 at 01:09

1 Answers1

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

should cure your problem.

or use ~nxx if you want the extension too.

Magoo
  • 77,302
  • 8
  • 62
  • 84