Windows 10

Batch File To Delete All Files In Folder

In this tutorial, you’ll learn how to delete all files in a specific folder using a simple batch script. This is useful for cleaning up directories such as temporary files, logs, or old data.

Batch files contain a series of DOS (Disk Operating System) instructions that automate tasks when executed.
 
 

🧾 Batch File to Delete All Files in a Folder

You can use the DEL command along with a wildcard (*.*) to delete all files in a given folder.
 
✅ Example: Delete All Files in the Folder myFiles

@echo off
DEL "C:\Users\StackHowTo\myFiles\*.*" /F /Q

📝 Output:
All files in C:\Users\StackHowTo\myFiles will be deleted. Subfolders will not be affected.

Option Description
*.* Matches all files in the folder, regardless of name or extension.
/F Forces deletion of read-only files.
/Q Quiet mode – no confirmation is asked.

 

⚠️ Important Notes
  • This command only deletes files, not folders or subfolders.
  • To delete files recursively (including subfolders), you’ll need to combine this with the for loop or use rd (remove directory) if desired.
  • Always test your script in a safe location before applying it to critical directories.
🕓 Common Use Cases
  • Deleting temporary or cache files.
  • Automated cleanup of logs.
  • File resets in a working directory.
🚀 Boost your productivity with the best AI toolsTry them

 

Leave a Reply

Your email address will not be published. Required fields are marked *