2012-12-26 43 views
0

因此,我需要在辦公室備份大約十幾臺舊電腦,並且沒有設置當前可用的網絡。我打算把所有東西都放到外置硬盤上,而且我通常只是使用以下內容。將所有驅動器上的文件/文件夾複製到外部驅動器?

xcopy C:\ F:\Backup /D /E /Y /EXCLUDE:BackupExclude.txt 

上面假定C:\是需要備份文件/文件夾的驅動器,F:\是外部硬盤。我正在尋找一種方法來實現同樣的功能。

我想一個批處理腳本枚舉系統上的所有可用驅動器的每個分區,並使用XCOPY一切在計算機的名稱後,並與子目錄爲每個分區/邏輯命名的目錄複製到特定的外部硬盤驅動器駕駛。

我希望批處理腳本使用其序列號識別外部硬盤。

任何想法?

回答

3

那麼這裏是您的起點。這應該做你所問的一切。

@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 
相關問題