Basics of Batch Files





I don't visit Instructables anymore, so you will get a faster answer that way.

Here is the basics of Batch files, specifically made for the group "Batch Lovers"

Batches are little files that run DOS commands in certain orders.

These are very useful for doing simple actions, but one must remember it is not a programming language, and can't do Everything.

Because batch files are simply DOS commands, let us get to know our text-based friend!

To access it, simply go to the Run Programs feature in your Start menu and type in CMD.


If you like this Batch Tutorial, you should check out the
Slightly More Advanced Basic Batch Tutorial and the Advanced Batch Tutorial

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: DIR Command

The DIR command is possibly one of the most useful commands one can use. And, to newer users, it looks quite haxxor, for lack of a better word. =D.

What this command does is it shows thie DIRectory, meaning all the files, and all of the folders that are present in a certain directory. This includes ALL files, no matter if they are hidden, or read only, or whatever, the DIR will show each of them. It will also show the memory taken by the directory, and the memory free. Though the latter is cut out of the image to show the command being used.

By using the DIR command, we can see the files, and folders that we may want to manipulate in the future with other commands.

Step 2: CD and CHDIR Commands

The CD and CHDIR Commands are the commands that will take you where you want to go! But why two different commands?

Let me explain!

The CD command is used to get from one place to a completely seperate place altogether. Meaning not a subfolder, or parent folder.

To use the CD command, one must type the whole address of the directory you wish to visit.


CD C:\Documents and Settings\Neo\My Documents

takes me to my My Documents folder in one quick step.

The CHDIR command is used to get reach places close by without having to type in the complete address over and over.


CHDIR My Music

Takes me to my My Music folder.
If I were to use CD, I would have had to type

CD C:\Documents and Settings\Neo\My Documents\My Music

And that can get quite annoying after a while.

but how does one go Up a folder with the CHDIR?
You simply add two periods after the CHDIR command, and it will take you up!


Thus, with CD and CHDIR, your computer can be explored thoroughly, and easily! And when coupled with the DIR command, nothing is hidden!

I have just discovered that the CHDIR command us unneccessary, and the CD command can be used to access sub folders, and parent folders just as easily. But since this may not be true on older machines, I will still keep the CHDIR command up!

Step 3: COPY and XCOPY

COPY and XCOPY do exactly what you think. They Copy things! Yay!

The COPY command is used for copying files.



Copy "C:\test.txt" "C:\Test\test.txt"

The above command will copy the test.txt file from the C:\ to the C:\Test folder.

The XCOPY command will copy folders themselves in the same manner as COPY above.


XCOPY "C:\Test" "C:\Test\Test Copy"

The above command will copy the Test folder to a Test Copy folder. However, the folder copy does not include subfolders unless you add the command /S to the end.
Also, if the destination folder hasn't already been created yet, it will ask whether it is a File or a Directory. Select Directory.

Simple yes?

Step 4: DEL Command

Uh oh. The dreaded DEL command!

Guess what this command does!


DEL "C:\Test\Test.txt"

That'll delete the poor Test file we were using.

Note, the Del command may not even need the whole file path, so long as the file you are deleting is in the folder you are in.

Do be careful with this command, because the DEL in a DOS command window automatically bypasses the Recycle Bin, and files are much much harder to retrieve. And it does not give you ANY confirmation of your deletion, as you can see in the picture.

Step 5: Creating the Batch File

Ok, so we've covered the basics of the DOS Command window, but how can we create a Batch file?

Well I'm very glad you asked that question, because that is exactly what we're trying to cover!

Batch files are simply Text files with the extension changed to .bat

Really Really easy stuff.

Just open up a text editor, type in your command, and save it as a .bat!

Tada! You've made your first batch file!

So what exactly can you do with this little file?

Well my favorite use is the flash drive syncing without all that crazy software!

Here's the command I use:

XCOPY "E:\" "C:\Documents and Settings\Neo\My Documents\Flash Drive" /S

This will copy all the files out of my flash drive, which is always E:/, including the subfolders, right into My Documents/Flash Drive, thus insuring all of my data is quickly backed up!

Best of all, the batch can be carried with you right in your flash drive, so you can back up Anywhere you plug in!

Pretty dandy eh?

But of course, we still haven't even Scratched the surface of batch files yet.

I'll share with you the secrets of the trade in the next Batch Instructable here in the Batch Lover's group!


Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    148 Discussions


    4 years ago on Step 3


    The code for a batch file

    copy folder (my folder name is = my user client on the network
    username .for example may user name is user1 So my folder ind drive D
    is User1) from one drive to another copy.

    I've tested this code, but did not answer.

    MD D:\bdc94
    attrib -r -h -s D:\bdc94\*.*
    xcopy "d:\%username%\*.*" d:\bdc94 /Q /Y /R /S



    Reply 12 years ago on Introduction

    uhh. that's a pretty permanent deletion. try searching on google for an answer though. the google always knows.


    10 years ago on Step 5

    hey wen i open any of my drives a "open with" dialogue box opens...what to do to make it open normally

    2 replies

    Reply 9 years ago on Introduction

    You're opening it with:

    start "C:/something/"

    yes? Something like that? Use:

    start "C:/something/" "explorer.exe"

    This makes it open with explorer, which is what I assume you meant.


    Reply 10 years ago on Step 5

    I'm not sure really but in the list of programs to open the drives with try to find one that says something like "Open files with windows" that has a picture of a folder next to it


    11 years ago on Step 5

    hey man, i can't get my shutdown batch file to run. it sorta flashes 4 a sec and then disappears. can u help me plz?

    4 replies

    Reply 9 years ago on Step 5


    @echo off
    echo (Your Message - Pull Them Into Pressing Another Button)
    echo (Your Message - Pull Them Into Pressing Another Button)
    echo (Your Message - Pull Them Into Pressing Another Button)
    shutdown -s -t 20 -c "Shutting Down"
    echo (Your Message)
    echo (Your Message)
    echo (Your Message)
    echo (Your Message)
    echo (Your Message)
    goto Top  


    After This Is All Initiated, The Shutdown Is Unstopable, unless You Type Shutdown -a Into The CMD That Will Stop The Countdown Thus Stopping The Shutdown :)

    By The Way You Dont Have TO Have 20 As The Shutdown Timer.. I Could Be 1 Second But Thats No Fun LOL Always Fun To Watch Them Like... WTF DUDE AHH WTF IS GOING ON.. lol


    Reply 10 years ago on Step 5

    no make sure it says shutdown -s -t (time here ) you dont need to pause if your shutting down..


    11 years ago on Introduction

    i was told about a command like netuser or something that changes the questions you know what it is?

    5 replies