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?
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)
just use
DIR D:\Project\Java\ /b
the result will be just like what you want