Tag Archive for 'batch files'

Batch Backup

Over the summer I did a load of new deploy systems and grew tired of backing things up by hand. So what would any nerd do? Well this nerd created a few batch files that will backup files to a flash drive for transportation to a new computer with minimal efforts.

[WARNING]

This file deletes certain shortcuts and all media from a users “My Documents” folder since it was used on a corporate network, this is not a bug, it is a feature.

The code is as follows;

setlocal
::loop through user accounts
::declare variable below
set ProfileFolder=%ALLUSERSPROFILE:\All Users=%
::for F times do this action until there are no more user accounts
for /f "delims=" %%a in ('dir "%ProfileFolder%\." /b') do (
::assign the folder address
echo "%ProfileFolder%\%%a"
::assign the computer name
echo "%computername%"
::Delete old shortcuts that will not be on the new computers
del "%ProfileFolder%\%%a\Desktop\Micro*.*" /F /Q
del "%ProfileFolder%\%%a\Desktop\TABS*" /F /Q
del "%ProfileFolder%\%%a\Desktop\All-*" /F /Q
::Delete all music files that shouldn't be on computers to begin with
del "%ProfileFolder%\%%a\Desktop\*.mp*" /F /S /Q
del "%ProfileFolder%\%%a\Desktop\*.w*" /F /S /Q
del "%ProfileFolder%\%%a\My Documents\My Music\*.*" /F /S /Q
del "%ProfileFolder%\%%a\My Documents\*.mp*" /F /S /Q
del "%ProfileFolder%\%%a\My Documents\*.w*" /F /S /Q
::Backup appropriate folders & Files into the Backup folder
xcopy "%ProfileFolder%\%%a\Desktop\*.*" "..\%computername%\%Folder%\%%a\Desktop\" /e /f /c /h /k
xcopy "%ProfileFolder%\%%a\Favorites\*.*" "..\%computername%\%Folder%\%%a\Favorites\" /e /f /c /h /k
xcopy "%ProfileFolder%\%%a\My Documents\*.*" "..\%computername%\%Folder%\%%a\My Documents\" /e /f /c /h /k
)
::finally copy all the shared docs to the external media
xcopy "C:\Shared Docs\*.*" "..\%computername%\Shared Docs\" /e /f /c /h /k

All you have to do is copy the above into a text file and name it with a .bat extension or you can download the version here.

grab_user_files.bat download