Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get filename in batch for loop

I have the following For loop in a batch file:

for /R c:\test\src %%i IN (*.*) DO ( MOVE %%i C:\test\destination ECHO %%i exit ) 

The result of the ECHO outputs the entire file path Ex: C:\Foldername\Filename I need to ECHO out only the Filename.Is there a specific command which would give me the filename ? Thanks !

like image 613
Murtaza Mandvi Avatar asked Jul 08 '09 20:07

Murtaza Mandvi


1 Answers

When Command Extensions are enabled (Windows XP and newer, roughly), you can use the syntax %~nF (where F is the variable and ~n is the request for its name) to only get the filename.

FOR /R C:\Directory %F in (*.*) do echo %~nF 

should echo only the filenames.

like image 136
AKX Avatar answered Oct 14 '22 16:10

AKX