Advanced File Copying With Batch Files!




Introduction: Advanced File Copying With Batch Files!


Hey everyone! today I will be showing you how to make a file copying batch file (mine is on a 32 GB flash drive). so basically, what I intended was to make a file that would back up my computer quickly and easily just by clicking on the file. The following commands will be used:

- Color

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Choose the Folders and or Files You Want to Back Up.

In the red rectangles are the folders I chose to back up. Here is the first bit of code you will want to type into your notepad.

@echo off
:: variables
SET odrive=%odrive:~0,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y
%backupcmd% "%USERPROFILE%\pictures" "%drive%\User Files\Photos"

What this is doing is telling the computer to copy the folders you selected and everything inside them, and save it to your flash drive. I recommend a flash drive with at least 8 GB for this project, depending on how many files you have. This is the most complicated step. the line of code below is telling the computer what you want to copy. you can change it to your preference.

%backupcmd% "%USERPROFILE%\pictures" "%drive%\User Files\Photos"

this code is going to save my pictures onto my flash drive in a folder called /User_files/Photos which can be changed very easily like this

%backupcmd% "%USERPROFILE%\Videos" "%drive%\User Files\Videos"

See how I changed pictures to videos? It's that simple. Shown in the picture above, highlighted in red, are all the folders I chose to back up. here is the full strip of code.

%backupcmd% "%USERPROFILE%\pictures" "%drive%\User Files\Photos
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\User Files\Favorites"
%backupcmd% "%USERPROFILE%\documents" "%drive%\User Files\Documents"
%backupcmd% "%USERPROFILE%\videos" "%drive%\User Files\Videos"
%backupcmd% "%USERPROFILE%\downloads" "%drive%\User Files\Downloads"
%backupcmd% "%USERPROFILE%\desktop" "%drive%\User Files\Desktop"
%backupcmd% "%USERPROFILE%\onedrive" "%drive%\User Files\OneDrive"

This is copying my Photos, Favorites, Documents, Videos, Downloads, Desktop, and OneDrive files. DO NOT FORGET TO SAVE AS A .BAT FILE. THIS IS ESSENTIAL.

Step 2: My Finishing Tweaks.

Well congratulations! If you have made it this far you have done great! All of the stuff you have just done was just the mandatory things. Now I will be showing you how I made into an actual program that you interact with!

Lets start with the Title command.
At the start of every folder being copied, I title the command prompt to tell me what is being copied. it will look something like this:

title Copying photos...
%backupcmd% "%USERPROFILE%\pictures" "%drive%\User Files\Photos"
title Copying Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\User Files\Favorites"
title Copying Documents...
%backupcmd% "%USERPROFILE%\documents" "%drive%\User Files\Documents"
title Copying Videos...
%backupcmd% "%USERPROFILE%\videos" "%drive%\User Files\Videos"
title Copying Downloads...
%backupcmd% "%USERPROFILE%\downloads" "%drive%\User Files\Downloads"
Title Copying Desktop...
%backupcmd% "%USERPROFILE%\desktop" "%drive%\User Files\Desktop"
title Copying OneDrive...
%backupcmd% "%USERPROFILE%\onedrive" "%drive%\User Files\OneDrive"

Do you see all the Title copying photos, copying videos, copying downloads, etc. These are optional, but it makes you look more professional.

Step 3: More Finishing Tweaks.

Remember how I said you can interact with it? Well here it is. What I made is a question in the batch file to ask me at the end "would you like to shutdown[Y/N]? If you type Y, hit enter it will shut down in ten seconds. If you type N, and hit enter, the file will close and all your files will be backed up! pretty cool, huh. You can also type COLOR A to give the font a cool looking green. So here is the "shutdown choice" command.

set /P c=Files have been copied. Would you like to shutdown[Y/N]?
if /I "%c%" EQU "Y" goto :Yes
if /I "%c%" EQU "N" goto :No
goto :choice
echo Shuting down...
Shutdown -s -t 10 -c "Data transfer complete. Windows will shutdown in 10 seconds.

What this is saying is that if you choose yes it will shut down you computer, but if you type no, it will exit.

Step 4: Your Finished Product.

Great job! If you have made it this far you are an expert batch programmer! I have included a video I shot of my script working and everything. This is my first instructable, so please comment and tell me what I can improve on and if you liked it! Thanks for reading.

Be the First to Share


    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    2 Discussions


    4 years ago on Introduction

    This is my first instructable and im all ears for suggestions!


    Reply 4 years ago on Introduction

    If anyone needs help I will try to help you. Just leave a comment on what your problem is!