robocopy /xd 没有按预期工作并且 robocopy 从当前复制文件

问题描述 投票:0回答:0

我有这个批处理脚本,用于从连接到系统的所有驱动器备份图像文件,不包括当前驱动器(运行脚本的驱动器)和 C:\Windows,到目标文件夹,这是一个名为“ images”,它位于运行脚本的同一驱动器中。但是,我需要帮助的代码有两个问题。中间注意我希望这个脚本动态运行。

第一个问题是脚本从 C:\Windows 文件夹复制文件,这是不应该的。该脚本使用“robocopy”命令将图像文件从源路径中找到的每个文件夹复制到目标路径。但是,它不排除 C:\Windows 文件夹,它不应该提到我添加了 /XD 属性。如何修改脚本以从复制过程中排除 C:\Windows 文件夹?

第二个问题是脚本从运行脚本的驱动器复制文件,这不是预期的行为。该脚本使用“%~dp0”变量获取脚本运行所在目录的驱动器号。我如何修改脚本以使所有驱动器连接到系统,并从复制过程中排除当前驱动器?

这是我到目前为止的代码:



@echo off 

setlocal enabledelayedexpansion

rem Find the drive this script is running from

set "drive=%~dp0"

set "drive=%drive:~0,2%"

rem Set the source and destination paths

set "destinationPath=%drive%\Images"

set "sourcePaths="

rem Get all drives attached to the system, excluding the current drive

for /f "skip=1 delims=" %%d in ('wmic logicaldisk get caption') do (

  if not "%%d\"=="%drive%\" set "sourcePaths=!sourcePaths!%%d\ "

)

rem Get all folders in the source paths to destination path 

for %%d in (!sourcePaths!) do (

  for /d %%f in ("%%d*") do (

    rem Copy image files from each folder to the destination path

    robocopy "%%f" "%destinationPath%" *.jpg *.jpeg *.png *.gif /S /z /XO /XD "C:\Windows" 

  )

)

任何帮助将不胜感激。提前谢谢你!

我尝试 /XD 排除 C:\Windows 目录,并尝试“如果不是”不从当前驱动器复制,但它没有用。

batch-file backup robocopy
© www.soinside.com 2019 - 2024. All rights reserved.