What a .bat file is and why you might create one

A .bat file is a text file that contains a list of commands Windows runs one after another, without you typing each one. The ".bat" stands for batch. You create it by writing plain text commands into a file, saving it with a .bat extension instead of .txt, and then double-clicking it to run all those commands at once.

People create .bat files to automate repetitive tasks — backing up folders, renaming multiple files, launching several programs at startup, or running the same sequence of commands every day. Instead of typing the same ten commands each morning, you click one file and it does all of them.

You do not need special software. Notepad, which comes with Windows, is enough. The commands themselves are the same ones you would type into Command Prompt or PowerShell, just saved in a file so Windows can read and execute them in order.

Key Takeaways

  • Open Notepad, type your commands (one per line), and save the file with a .bat extension instead of .txt to create a working batch file.
  • Use commands you would normally type into Command Prompt, such as cd to change folders, copy to copy files, or dir to list files.
  • Double-click the .bat file to run all commands in order, or right-click and choose "Run as administrator" if the commands need higher permissions.
  • A command window opens while the batch file runs; if it closes too fast to read, add pause as the last line so it waits for you to press a key.

Creating a .bat file in Notepad

Open Notepad by pressing the Windows key, typing "notepad", and pressing Enter. A blank text window appears. Type each command on its own line, in the order you want Windows to run them.

For example, if you want to create a folder called "Backup" on your Desktop and then copy all files from your Documents folder into it, you would type:

cd Desktop mkdir Backup copy "C:\Users\YourUsername\Documents\*.*" Backup

Replace "YourUsername" with your actual Windows username. Each line is one command. Windows will run them top to bottom when you execute the file.

Once you have typed all your commands, click File, then Save As. In the "Save as type" dropdown at the bottom, change it from "Text Documents (*.txt)" to "All Files (*.*)". In the filename field, type a name followed by .bat — for example, backup.bat. Click Save. The file is now ready to run.

Common commands to use in a .bat file

You do not need to memorize commands. Here are the ones people use most often in batch files:

CommandWhat it doesExample
cdChange to a different foldercd C:\Users\YourUsername\Desktop
mkdirCreate a new foldermkdir MyNewFolder
copyCopy a file or filescopy file.txt C:\Backup
delDelete a filedel oldfile.txt
dirList all files in the current folderdir
pauseStop and wait for you to press a keypause
echoPrint text to the screenecho Backup complete
startOpen a program or filestart notepad.exe

If a folder or filename has spaces in it, put the whole path in quotation marks: copy "My Documents\file.txt" Backup. This tells Windows to treat the whole thing as one name, not separate words.

Running your .bat file

Navigate to the folder where you saved your .bat file. Double-click it. A command window opens and runs each command in order. You will see text appear as each command executes.

If the window closes immediately and you did not see what happened, add the word pause as the last line of your batch file. When Windows reaches that line, the window will stay open and display "Press any key to continue . . ." until you press a key. This gives you time to read any messages or errors.

If a command needs administrator permissions — for example, if it modifies system files — right-click the .bat file and choose "Run as administrator" instead of double-clicking. Windows will ask for permission, and then run the file with higher access.

Editing a .bat file after you create it

To change the commands in your .bat file, right-click it and choose "Edit". Notepad opens with the file contents. Make your changes, then save the file (Ctrl+S). The next time you run it, the new commands will execute.

Do not double-click a .bat file to edit it — that runs it instead. Always right-click and choose Edit, or open Notepad first and then open the file from inside Notepad using File > Open.

Troubleshooting when a .bat file does not work

If your batch file runs but nothing happens, or you see an error message, the most common causes are wrong folder paths, missing quotation marks around names with spaces, or typos in command names.

Add pause at the end so the window stays open long enough to read error messages. The error message usually tells you which line failed and why. Check that line for misspelled folder names or commands. If a path is wrong, use the full path starting from C:\ instead of a relative path.

If you see "Access Denied", the command needs administrator permissions. Right-click the .bat file and choose "Run as administrator".

Frequently Asked Questions

Can I run a .bat file from a USB drive or network folder?

Yes. Save the .bat file to the USB drive or network location and double-click it from there. If the commands reference other files, use full paths (starting with C:\ or the network address) rather than relative paths, so Windows knows where to find them no matter where the batch file is stored.

What if I want the command window to stay hidden while the .bat file runs?

Create a shortcut to your .bat file, right-click the shortcut, choose Properties, click Advanced, and check "Run as administrator" if needed. Then in the Shortcut tab, change the "Run" dropdown from "Normal window" to "Minimized" or "Hidden". Double-click the shortcut instead of the .bat file itself.

Can I schedule a .bat file to run automatically at a certain time?

Yes, using Windows Task Scheduler. Press Windows key + R, type "taskschd.msc", and press Enter. Click "Create Basic Task", give it a name, set the trigger (time and frequency), and in the Action section point it to your .bat file. Windows will run it automatically on that schedule.

Is it safe to run .bat files from the internet?

Only run .bat files from sources you trust. A batch file can delete files, change settings, or install software, so a malicious .bat file could damage your system. If someone sends you a .bat file, open it in Notepad first and read the commands to understand what it does before running it.