问题
My code is
SET usb="%CD%\Dokument\%USERNAME%\"
mkdir %usb%
for /R "C:\Users\%USERNAME%\" %%f in (*.docx) do copy %%f %CD%\Document\%USERNAME%\
and it works, but not for files (.docx) with spaces in their name. I've tried fixing it with quotes, and different code styles/methods, but can't solve it. (I'm new to DOS). How can I solve this?
Or is there a better code to copy all the files with .docx extension from a computer to another directory/usb?
回答1:
You need to quote file paths containing spaces, i.e. copy "%%f"
This may do what you wanted:
Set "USB=%~dp0Dokument\%USERNAME%"
If Not Exist "%USB%\" MD "%USB%" 2>&1||Exit/B
For /F "Delims=" %%A IN ('Where/R "%USERPROFILE%" *.docx'
) Do Copy/Y "%%A" "%USB%">Nul
来源:https://stackoverflow.com/questions/47392473/copy-files-w-spaces-in-name