Batch file 是否将所有驱动器上的文件/文件夹复制到外部驱动器?

Batch file 是否将所有驱动器上的文件/文件夹复制到外部驱动器?,batch-file,Batch File,所以,我需要备份办公室里的十几台旧电脑,而目前还没有可用的网络设置。我计划把所有东西都放在外置硬盘上,我通常只使用下面的方法 xcopy C:\ F:\Backup /D /E /Y /EXCLUDE:BackupExclude.txt 以上假设C:\是需要备份文件/文件夹的驱动器,F:\是外部硬盘。我正在寻找一种方法来实现同样的自动化 xcopy C:\ F:\Backup /D /E /Y /EXCLUDE:BackupExclude.txt 我想要一个批处理脚本,它枚举系统上所有可用驱

所以,我需要备份办公室里的十几台旧电脑,而目前还没有可用的网络设置。我计划把所有东西都放在外置硬盘上,我通常只使用下面的方法

xcopy C:\ F:\Backup /D /E /Y /EXCLUDE:BackupExclude.txt
以上假设C:\是需要备份文件/文件夹的驱动器,F:\是外部硬盘。我正在寻找一种方法来实现同样的自动化

xcopy C:\ F:\Backup /D /E /Y /EXCLUDE:BackupExclude.txt
我想要一个批处理脚本,它枚举系统上所有可用驱动器的每个分区,并使用xcopy将所有内容复制到以计算机名称命名的目录中的特定外部HDD中,每个分区/逻辑驱动器都有子目录

我希望批处理脚本使用其序列号识别外部HDD


有什么想法吗?

好吧,这是你的出发点。这应该满足你的要求

@echo off
setlocal EnableDelayedExpansion

rem Loop through all of the drives to find the external HDD
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    for /f "tokens=5" %%S in ('vol %%~D:') do set "xSerial=%%S"
    if "%xSerial%"=="ABCD-1234" (
        rem TODO Specify the target copy base location
        set "xTarget=%%~D:\%ComputerName%"
    )
)

rem Loop through all of the drives, skipping the external HDD
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    for /f "tokens=5" %%S in ('vol %%~D:') do set "xSerial=%%S"
    if not "%xSerial%"=="ABCD-1234" (
        pushd "%%~D:\" 2>nul
        if !ErrorLevel! EQU 0 (
            mkdir %xTarget%\%%~D
            xcopy "%%~D:\" "%xTarget%\%%~D" /D /E /Y /EXCLUDE:BackupExclude.txt
        )
        popd
    )
)
endlocal
pause

这是你的一个起点。这应该满足你的要求

@echo off
setlocal EnableDelayedExpansion

rem Loop through all of the drives to find the external HDD
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    for /f "tokens=5" %%S in ('vol %%~D:') do set "xSerial=%%S"
    if "%xSerial%"=="ABCD-1234" (
        rem TODO Specify the target copy base location
        set "xTarget=%%~D:\%ComputerName%"
    )
)

rem Loop through all of the drives, skipping the external HDD
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    for /f "tokens=5" %%S in ('vol %%~D:') do set "xSerial=%%S"
    if not "%xSerial%"=="ABCD-1234" (
        pushd "%%~D:\" 2>nul
        if !ErrorLevel! EQU 0 (
            mkdir %xTarget%\%%~D
            xcopy "%%~D:\" "%xTarget%\%%~D" /D /E /Y /EXCLUDE:BackupExclude.txt
        )
        popd
    )
)
endlocal
pause