Skip to content

Instantly share code, notes, and snippets.

@davidruhmann
Created December 26, 2012 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidruhmann/4382806 to your computer and use it in GitHub Desktop.
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.
@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