Copy Files /w Spaces In Name

不问归期 提交于 2021-01-28 08:38:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!