Prax
Prax

Reputation: 91

Avoiding path name to be print with for Loop in Batch

I have used for loop for my script as given below:

for /f "tokens=* delims= " %%G In ('dir /a-d/b/s "%dest%\*.*"') do (
    echo %%G >>%save_file%
)

Now when i am running this job it is printing path name of the files. I want to save only files name not the path.

Upvotes: 0

Views: 35

Answers (2)

JosefZ
JosefZ

Reputation: 30113

This could work:

for /f "tokens=* delims= " %%G In (
    'dir /a-d/b/s "%dest%*.*"'
) do ( echo %%~nxG >>%save_file% )

Resource for all modifiers.

Upvotes: 1

Stephan
Stephan

Reputation: 56180

echo %%~nxG

Those modifiers are described in for /?

Upvotes: 1

Related Questions