Created
December 26, 2012 20:11
-
-
Save davidruhmann/4382806 to your computer and use it in GitHub Desktop.
[Batch] Copy contents for all of a systems drives onto a specified external HDD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 exact target copy base location that you want. | |
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" ( | |
rem Attempt to gain access to the drive if it exists. | |
pushd "%%~D:\" 2>nul | |
if !ErrorLevel! EQU 0 ( | |
rem Make the target directory and copy. | |
mkdir %xTarget%\%%~D | |
xcopy "%%~D:\" "%xTarget%\%%~D" /D /E /Y /EXCLUDE:BackupExclude.txt | |
) | |
popd | |
) | |
) | |
endlocal | |
pause | |
:: by David Ruhmann |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment