I want to traverse all files within a specific directory and all its subdirectories and then print out the folder name of each file.
I don't know how to get the folder name of each file.
FOR /F "delims=" %%x IN ('dir /B /A /S *') DO (
:: Suppose %%x is 'C:\myfolder\a.txt', the desired output is 'myfolder'
:: %%~nx is not correct
echo ???
)
nis for filename. Checkfor /?for other options. You can combine the different options. You probably look for%%~dpxFORcommand?DOSis an Operating System from the 80s/90s! Please use the tag Windows instead.