Is there Any way I can bypass displaying file paths when using the dir /b /s command into a file?
Currently, when I run dir /b /s C:\WinPE_amd64 >dir.txt it outputs something like this:
C:\WinPE_amd64\file.txt
C:\WinPE_amd64\secondfile.txt
C:\WinPE_amd64\Folder\AnotherFile.txtWhat I want is something like this:
file.txt
secondfile.txt
AnotherFile.txt 2 1 Answer
Parse dir output with a for /f and use the ~nx modifier to return only name+extension
On the cmd line:
(for /f "delims=" %A in ('dir /B/S "C:\WinPE_amd64"') do @Echo=%~nxA)>dir.txtIn a batch double the percent sign of the for metavariable
@Echo off
( for /f "delims=" %%A in ('dir /B/S "C:\WinPE_amd64"') do Echo=%%~nxA
) >dir.txtIt is a matter of formatting preference (or to avoid overly long lines)
@Echo off
( for /f "delims=" %%A in ( 'dir /B/S "C:\WinPE_amd64"' ) do Echo=%%~nxA
) >dir.txtEDIT a possibly faster alternative is a for /r
(For /r "C:\WinPE_amd64" %A in (*) Do @Echo=%~nxA)>dir.txtAnother alternative wrapping a powershell command
powershell -nop -c "(dir 'C:\WinPE_amd64' -r -file).Name" >dir.txt 3