What a batch file does and why you might need one
A batch file is a text document that contains a list of commands your computer runs one after another, without you typing each one. Windows reads the file and executes every instruction in order. The most common reason to create one is to automate a task you do the same way every day — moving files from your Downloads folder to organized subfolders, backing up specific directories, or opening the same set of programs when you start work.
Batch files run on Windows only. They have a .bat extension (like organize-files.bat) and live as plain text, which means you can create and edit one in Notepad without any special software. When you double-click a batch file, Windows Command Prompt opens, reads your commands, and carries them out.
The payoff is time: a task that takes five minutes by hand takes five seconds once a batch file runs it. If you organize files the same way weekly, or back up the same folders monthly, a batch file eliminates the repetition.
Key Takeaways
- Batch files are plain text documents you create in Notepad and save with a .bat extension that Windows Command Prompt can read and execute.
- Common batch file commands include cd to change folders, copy to duplicate files, move to relocate them, and del to delete them.
- You write one command per line, and Windows runs them in order from top to bottom each time you double-click the file.
- Test your batch file on a copy of your files first, because mistakes can move or delete files you did not intend to touch.
Opening Notepad and writing your first batch file
Start by opening Notepad. Press the Windows key, type notepad, and press Enter. A blank text window appears. This is where you write your commands.
Every batch file starts with a single line that tells Windows to hide the commands as they run. Type this as your first line:
@echo off
This prevents a wall of text from scrolling across your screen while the batch file works. Without it, you see every command printed out, which is distracting but harmless.
On the next line, add a comment — a note to yourself about what this file does. Comments start with rem (short for remark). Type:
rem This batch file moves files from Downloads to organized folders
Comments do nothing when the file runs; they exist only to remind you later what you were trying to do. Add as many as you need.
Understanding the commands you will use most
Batch files use a small set of commands that handle almost every file task. The most important ones are cd (change directory), copy, move, and del (delete). Learning these four covers 90 percent of what people automate.
cd moves you into a folder. If you want to work with files in your Downloads folder, you write:
cd C:\Users\YourUsername\Downloads
Replace YourUsername with your actual Windows username. You can find this by opening File Explorer, clicking "This PC" on the left, and looking at the path bar at the top — it shows your username after Users.
copy duplicates a file. This command copies a file called report.docx from your current folder to a subfolder called Archive:
copy report.docx Archive\report.docx
move relocates a file instead of copying it. This removes the file from where it started and puts it in the new location:
move report.docx Archive\report.docx
del deletes a file permanently. Use this carefully — deleted files do not go to the Recycle Bin when a batch file deletes them:
del report.docx
You can also use wildcards to work with multiple files at once. The asterisk * means "any characters". This command moves every .pdf file in your current folder to an Archive subfolder:
move *.pdf Archive\
Building a complete batch file example
Here is a real batch file that organizes files in your Downloads folder by type. Copy this into Notepad exactly as written:
@echo offrem Organize Downloads folder by file typecd C:\Users\YourUsername\Downloadsif not exist Documents mkdir Documentsif not exist Images mkdir Imagesif not exist Archives mkdir Archivesmove *.docx Documents\move *.xlsx Documents\move *.pdf Documents\move *.jpg Images\move *.png Images\move *.zip Archives\echo Organization complete
Replace YourUsername with your actual Windows username. The if not exist lines check whether each folder exists before trying to move files into it. If the folder does not exist, mkdir creates it. The last line, echo Organization complete, prints a message when the batch file finishes so you know it ran successfully.
This file moves Word documents, Excel spreadsheets, and PDFs into a Documents folder; JPG and PNG images into an Images folder; and ZIP files into an Archives folder. Any files that do not match these types stay where they are.
Saving your batch file with the correct extension
In Notepad, click File, then Save As. A dialog box opens. At the bottom, you see a dropdown that says "Save as type:" and currently shows "Text Documents (*.txt)". Click that dropdown and select "All Files (*.*)". This lets you save with a .bat extension instead of .txt.
In the filename field, type a descriptive name followed by .bat. For example:
organize-downloads.bat
Choose where to save it. Many people save batch files on the Desktop or in a Batch Files folder in Documents so they can find them easily. Click Save.
Do not save it in the Downloads folder itself if your batch file moves files out of Downloads — that can cause problems. Save it somewhere separate, like your Desktop.
Testing your batch file safely before using it
Before you run a batch file on your real files, test it on copies. Create a test folder on your Desktop, copy a few sample files into it, and modify your batch file to point to that test folder instead of your real Downloads folder. Run the test version and watch what happens.
To run your batch file, double-click it. A Command Prompt window opens, runs your commands, and closes when finished. If something goes wrong, you have only affected your test files, not your actual documents.
Common mistakes include typing a folder path wrong (which causes "file not found" errors), forgetting to create destination folders (which causes the move to fail), or using the wrong wildcard (which moves files you did not intend to touch). Testing catches all of these before they matter.
Once you are confident the batch file works correctly, you can modify it to point to your real folders and run it on your actual files.
Running your batch file on a schedule
After you have tested your batch file and it works, you can set Windows to run it automatically on a schedule. This is useful if you organize files weekly or back up folders monthly and want it to happen without you remembering to do it.
Right-click your batch file and select "Create shortcut". A new file appears with "— Shortcut" in the name. Right-click that shortcut and select "Properties". In the window that opens, click the "Advanced" button, check the box next to "Run as administrator", and click OK. This ensures the batch file has permission to move or delete files.
To schedule it, press the Windows key, type Task Scheduler, and press Enter. Click "Create Basic Task" on the right side. Give it a name, choose when you want it to run (daily, weekly, monthly), and in the "Action" section, browse to your batch file shortcut. Windows will now run your batch file automatically on the schedule you set.
Frequently Asked Questions
What is the difference between copy and move in a batch file?
Copy leaves the original file where it is and creates a duplicate in the new location. Move removes the file from the original location and puts it in the new one. Use copy when you want to keep a backup; use move when you want to organize files into their final folders.
Can I undo a batch file if it deletes files by mistake?
No. Files deleted by a batch file do not go to the Recycle Bin — they are gone permanently. Always test your batch file on copies of your files first, and be very careful with the del command. If you are unsure, use move instead of del.
Why does my batch file say "file not found" when I run it?
The most common cause is a typo in the folder path or filename. Double-check that your username is spelled correctly in the path (C:\Users\YourUsername\...) and that folder names match exactly, including capitalization. Open File Explorer and copy the path directly from the address bar to avoid mistakes.
Can I run a batch file from a USB drive?
Yes, but paths become tricky because USB drives get different letters (D:, E:, F:) depending on what other drives are plugged in. If you save your batch file on a USB drive, use relative paths (like just the folder name without C:\Users\...) or write the batch file to detect which drive letter the USB has. For most people, keeping batch files on your computer is simpler.
What happens if I double-click a batch file by mistake?
It runs when ready. This is why you should keep batch files somewhere you can see them (like your Desktop) rather than buried in a folder, so you do not accidentally trigger one. If a batch file starts running and you want to stop it, click the Command Prompt window and press Ctrl+C to cancel.