I made this command to move specified files in all subfolders to a specified destination and then delete all empty subfolders.
Copying all PDF-files in subfolders into current dir
for /f "tokens=*" %d in ('dir *.pdf /b/s') do move /y "%d" .\
and then deleting all empty folders
for /f "tokens=*" %d in ('dir /ad/b/s ^| sort /R') do rd "%d"
The commands looks work well when I copy it and paste it into a command line, but not when I run it inside a batch file. What am I forgetting? And can I trust this command in all conditions?