By using:
dir /s /b /o:n /a:d > foldername.txt
I get the following output:
D:\Project\Java\MyName
D:\Project\Java\Object
But I want the output to look like this:
MyName
Object
The output have to be folder names without their paths?
The FOR loop has variable modifiers such that only the file name and extension can be presented. Note that a directory can have an extension. Use FOR /? for information about the variable settings.
FOR /F "usebackq tokens=*" %d IN (`DIR /S /B /A:D /O:N`) DO (ECHO "%~nxd")
Or, to put the names into a file without quoting:
DEL foldername.txt
FOR /F "usebackq tokens=*" %d IN (`DIR /S /B /A:D /O:N`) DO (ECHO>>foldername.txt %~nxd)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With