如果您打开 cmd.exe 并输入 xcopy /?,您将看到所有有效的开关,我不确定您尝试了哪些 xcopy 命令,但这毫无疑问应该可以工作:
xcopy /Y "E:\folder paths\file.pdf" "E:\Placetostay"
然而,我想知道为什么您需要将每一行添加到要复制的文件中?这是很多手动工作,以至于手动复制它可能更容易。那么为什么不自动化呢?
这里有一些想法。此脚本将在您的E:\ 驱动器上进行递归搜索,如果任何文件与名称 hotel 匹配,它会将其复制到相关目标,除非搜索的文件在目标中,只是因为我们不想再次将文件复制到它自己的路径,显然第二个选项也会为restaurants 执行此操作:
酒店:
@echo off
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i hotel') do (
if not "%%~dpi"=="E:\Placestostay\" xcopy "%%~fi" "E:\Placestostay"
)
餐厅:
@echo off
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i restaurant') do (
if not "%%~dpi"=="E:\Placestostay\" xcopy /Y "%%~fi" "E:\Placestoeat"
)
显然以上也可以组合。
然后,我们也可以这样做,但让您通过提示用户输入搜索条件来选择要搜索的内容:
@echo off
set /p "search=Select search type (hotel, restaurant etc.): "
set /p "destination=Enter the destination to copy to (E:\placestoeat\ etc.): "
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i %search%') do (
if not "%%~dpi"=="%destination%" xcopy /Y "%%~fi" "%destination%"
)
或者类似地,根据搜索预定义目标文件夹:
@echo off
set /p "search=Select search type (hotel, restaurant etc.): "
if /i "%search%"=="hotel" set "destination=E:\placestostay\"
if /i "%search%"=="restaurant" set "destination=E:\placestoeat\"
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i %search%') do (
if not "%%~dpi"=="%destination%" xcopy /Y "%%~fi" "%destination%"
)