我正在尝试使用完整文件路径列表(大多数是唯一的)(例如“C:\Folder1\file_1.xls”)复制到完整文件夹路径(例如“C:\DifferentFolder)。
完整文件路径和完整文件夹路径因行而异。通过将所有路径放在引号中,我已经使用 COPY 基本上成功地完成了这项工作。
COPY "E:\California\CA_restaurants.pdf" "E:\Placestoeat\"
COPY "E:\California\CA_hotels.pdf" "E:\Placestostay\"
COPY "E:\Arizona\AZ_hotels.pdf" "E:\Placestostay\"
继续使用它的问题是,当我查看 .bat 文件完成前后的文件数量时,我发现只有大约 95% 的成功率。我不确定问题是什么,但我正在考虑切换到 Robocopy 或 xcopy,因为我听说它们可以提供有关成功的反馈以及重命名重复文件的选项?
问题是,我似乎无法根据完整的文件名和完整的文件夹名称让 xcopy 或 robocopy 工作,这两者都会更改每一行。
有人可以解释我做错了什么或提供一个示例脚本供我尝试吗?我不是技术人员,只是想找到一种方法让我的平凡历史数据项目更有效率。
如果您打开 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%"
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句