🗃️ Automatic Backup Script
🎯 Learning Objective
- Learn to write a batch script to automate common tasks.
📜 Statement
Write a script named backup.bat that automates the backup of
all text files (.txt) present in a specific folder
(e.g., C:\Users\YourName\Documents) to a backup folder
(e.g., C:\Backups\).
Your script should perform the following tasks:
- Check if the backup folder exists; if not, create it.
- Copy all
.txtfiles to this folder. - Clearly display a success or failure message depending on the result of the operation.
- At the end, display the number of files copied.
The script should keep the CMD window open after execution to view the result.
⚙️ Suggested Commands:
if exist: Check if a folder exists.mkdir: Create a folder.copy: Copy files.dir: List files compactly.
🖥️ Example of Expected Result
When you run the backup.bat file, here is what you should see:
====================================
Automatic Backup
====================================
Creating backup folder...
The folder already exists.
Copying text files in progress...
3 file(s) copied.
Backup completed successfully!
Press any key to continue...
🚩 Bonus
- Add the current date to the backup folder (e.g.,
C:\Backups\2025-06-06\).