🚀 Automation in Windows with .BAT files
Simple examples and practical scenarios for beginners to automate everyday tasks
💡 What you will learn in this article
Discover how you can save time and simplify your daily computer work by creating simple files that automatically perform repetitive tasks. Without having to be a computer expert!
You'll learn step-by-step how to create and run batch files, automate processes like backups, file management, and run multiple commands with a single click. Plus, you'll see practical examples that you can immediately adapt to your needs.
By the end of this article, you will have the skills to create small tools that make your work more efficient, reducing errors and freeing up time for more important tasks.
📋 Article Contents
- 🤔 What are BAT files?
- 📝 How do I create a BAT file?
- 🧹 Example 1: Automatic Cleaning of Temporary Files
- (I.e. Example 2: Backing Up Your Files
- (I.e. Example 3: Bulk File Renaming
- 🌐 Example 4: Opening Multiple Web Pages at Once
- 📊 Example 5: Organizing Files by Type
- 🖥️ Example 6: Quick System Information
- ⏰ How to run automatically at a specific time
- ⚠️ Safety Tips
- 🎯 Conclusion
🤔 What are BAT files?
- Save valuable time from repetitive tasks
- They reduce the possibility of error (the computer doesn't forget steps!)
- No special programming knowledge required
- They are free and built into Windows
📝 How do I create a BAT file?
Creating a BAT file is very simple. Follow these steps:
Press the button Start Windows and type "Notepad". Open the program.
Write the commands you want the computer to execute (we will see examples below).
Go to the menu File → Save As. In the file name write something like to_programma_mou.bat (important that it ends in '.bat'). In "Save as type" select "All Files".
Double-click the .bat file you created and the commands will be executed automatically!
🧹 Example 1: Automatic Cleaning of Temporary Files
Over time, Windows accumulates temporary files, logs, caches, and junk data that eat up space and often slow down the system. The program below automatically cleans up many categories of such files with one click.
- Temp folder: files that create programs and are no longer needed
- C:\Windows\Temp: old Windows temporary files
- Prefetch: startup optimization files (regenerated automatically)
- Browser cache: Chrome & Edge cache taking up many MB/GB
- Windows Update cache: useless downloader files from old upgrades
- Recycle Bin: completely empties the Recycle Bin
Do not run this script while Windows updates are being installed. Prefetch and cache files are safe to delete — they will be recreated automatically.
- Deletes all temporary files from the Temp folder
- Emptying the Recycle Bin
- It informs you about every action it takes.
- It is waiting for you to press a key to close (pause)
💾 Example 2: Backing Up Your Files
Backing up is very important! The program below automatically copies your important files from a folder of your choice to a secure destination folder.
👉 You will only need to change two lines: the source folder and the destination folder.
- Copies all files from the folder you specify in
source - Automatically creates a folder with a date (e.g. 2025-11-16)
- Keeps subfolders as is
- Replaces old files only if they have changed
Change it set destination=... to your own destination folder.
Examples of safe options:
• External disk: E:\Backup
• USB Stick: F:\USB_Backup
• Second internal disk: D:\MyFiles\Backups.Make sure there is enough free space!
🔄 Example 3: Bulk Rename Files with Preview
This script does the same as before, but first displays what your files will be named so you can make sure they are correct before proceeding with the renaming.
- Shows preview of new names before renaming them
- Asks the user if they want to continue
- Bulk renames files in numerical order only if confirmed
- Safe for beginners, reduces the possibility of errors
- The line
cd /d "C:\Users\%username%\Pictures\Fotografia"determines which folder to look for files in. You can change the path to point to the folder containing your files. - The file mask
*.jpgonfor %%f in (*.jpg)selects all files with the extension .jpg in the folder. You can change it to*.png,*.mp3ή*.*for all files. - The script **doesn't have to be in the same folder as the files**. You can keep it in a separate folder and just change the
cd /don the desired route. - The user first sees the list of files and new names before any changes are made, and decides whether to continue with the
Y/N.
- You can add more file types, B.C.
for %%f in (*.jpg *.png). - You can change the base name
Vacation_Summer_2025to any desired. - You can preview only specific files by creating a separate mask, e.g.
IMG_*.jpg.
🌐 Example 4: Opening Multiple Web Pages with Preview
This script first shows the web pages it is about to open, so you can check that they are correct, and then asks you if you want to proceed.
- It first shows the list of websites to open
- Asks the user for confirmation before opening sites
- Opens web pages with a 1 second delay between them
- Safe for beginners and easy to adapt
- You can add or remove websites from the list
set websites=... - Change the delay time to
timeout /t 1if you want a longer interval between openings
📊 Example 5: Organizing Files by Type
The "Downloads" folder usually becomes a mess! This program automatically organizes all files into folders by type:
🔍 How It Works:
- cd /d "%userprofile%\Downloads" - Goes to the user's Downloads folder
- if not exist "Folder" mkdir "Folder" - Creates folder only if it doesn't already exist
- move *.extension "Folder\" - Moves all files with a specific extension to the corresponding folder
- 2>nul - Hides error messages (e.g. if there are no .mp3 files)
-
Add more extensions – If you want to organize other types of files, add new lines
move.
Example for graphics:move *.psd "Images\" 2>nul,move *.ai "Images\" 2>nul,move *.svg "Images\" 2>nulAll Photoshop, Illustrator and SVG files will go into the `Images` folder. -
Create new folders – If you want folders by topic or project, first create the folder with:
if not exist "School" mkdir "School"andif not exist "Work" mkdir "Work", and then moved the files there withmove. -
Change the folder path – To organize a folder other than Downloads, replace the command:
cd /d "%userprofile%\Downloads"with the path of the folder you want, e.g.cd /d "D:\Work\Projects". -
Add a date or timestamp to folders – Use the command
%date%ή%date:~-4%-%date:~-7,2%-%date:~-10,2%to create type foldersImages_2025-11-16and keep files organized by date.
🖥️ Example 6: Quick System Information
Want to quickly see information about your computer? This program creates a report with useful details, saves everything to a TXT file on the Desktop, and opens it automatically.
- Collects operating system details
- Displays processor (CPU) and RAM information
- Shows available space on hard drives
- Provides information about GPU (graphics card)
- Displays networks and connections (Network Adapters)
- List of installed programs with versions
- Shows active users in the system
- Saves everything to a TXT file on the Desktop
- Automatically opens the file for immediate viewing
- You can add network information:
netstat -an >> "%reportfile%" - You can collect details for services:
wmic service get name,startmode,state >> "%reportfile%" - Add date and time to file name to keep history: we already use
%date%and%time%
⏰ How to run automatically at a specific time?
You can set your programs to run automatically using the Task Scheduler Windows. This is useful for everyday tasks like cleaning, backing up, or organizing folders without having to do it manually.
Click Start and type "Task Scheduler". Open the program. On the home screen you will see the existing tasks and you can check which program is running automatically.
Click on "Create Basic Task" (Create Basic Task) in the right menu. Give it a descriptive name and a short description so you can remember what the task does later.
Choose when you want the task to run: Casual, Weekly, Only once or when an event occurs. Set the exact time, e.g. 23:00 to clean temporary files or 08:00 to open work web pages.
In the "Action" field, select "Start a program" and press Browse to find the file .bat that you want to run automatically. You can select any BAT file you have created, e.g. for cleaning, backup or folder organization.
- Every morning at 8:00: Opening work websites to start the day ready.
- Every Sunday at 22:00: Back up important files.
- Every day at 23:00: Clean up temporary files to free up space on your computer.
- Every Friday at 18:00 PM: Organize Downloads folder and sort files by type.
- Customized program: You can combine multiple tasks at different times or days, depending on your needs.
⚠️ Safety Tips
BAT files are powerful tools and can make changes to your system, so be careful. Follow these guidelines for safe use and to avoid problems.
- Do not run BAT files from strangers: Only your own or from trusted sources.
- Try first: Before using a new BAT file, test it on non-important files or folders.
- Keep backups: Before you do anything that deletes or moves files, make a backup.
- Read the code: Open the file with Notepad and see what it does before running it.
- Be careful on the routes: Make sure the folders you are using exist to avoid errors.
@echo on instead @echo off the first time you try it. This way you'll see every command being executed and understand exactly what the program does before you automate it.
- You can add notification actions, such as
msg %username% "Η εργασία ολοκληρώθηκε"to display a message after execution. - Use log files with
>> log.txtto record what was executed. - For more complex scripts, you can combine multiple BAT tasks into one program and have Task Scheduler execute them in sequence.
🎯 Conclusion
BAT files are a simple and free way to save time and make your daily computer work easier and more efficient. Start with the simple examples you saw here, experiment, and soon you'll be creating your own automations that fit your needs exactly!
📚 Resources & Learning for Scripts & BAT Files
If you want to delve deeper into scripting in Windows, better understand commands, and learn safe practices, you can utilize the following resources:
🌐 Websites:
- SS64 - Windows CMD Reference – Detailed Command Prompt command guide.
- Microsoft Scripting Center (Archive) – Official Microsoft site for scripting (archive/legacy).
- ComputerHope Batch File Tutorial – Beginner's guide with examples.
- TutorialsPoint - Batch Scripting – Step-by-step tutorials for beginners and advanced users.
- Stack Overflow - Batch File Questions – Ask or see solutions to problems and questions.
- PowerShell Gallery – Official library of modules and scripts for Windows PowerShell, ideal for more modern automations.
📖 Books:
- "The Book of Batch Scripting" – Jack McLarney — Available as a paperback with ISBN 9781718503427.
- "Batch Scripting Essentials: Definitive Reference" – Richard Johnson — Professional guide to scripting, available in e-book.
💡 Extra Tips:
- Experiment first with simple scripts in a test folder to see how the commands work.
- use it
@echo onto monitor each command as it executes. - Create backups before running scripts that delete or move files.
- Gradually add new commands and functions to automate everyday tasks.
Using these resources, you can learn to create safe and efficient scripts for any type of task, from simple folder cleanups to automated backups and bulk file renaming.
📌 Useful Shortcuts:
BAT = Batch File | CMD = Command Prompt | REM = Comment in code
Loading comments...