Skip to content

5000+ Great Articles

Best Articles & Essays: Interesting Articles to Read Online

  • Best learning resources pretend and play calculator cash register 2020 Calculator
  • How To Install & Use The New Windows 10 Terminal Windows 10
  • How to Fix the ( Settings app not opening in Windows 10 ) Windows
  • How to Boost Your Wi-Fi Network With an Old Router How-To
  • How to Screen Record Natively in Android 10 How-To
  • Fix End Tag Start Tag Mismatch Error When Opening DOCX Files Office Tips
  • How To Test If a PC Can Run a Game Gaming
  • Best yugioh calculator case 2020 black

How to Automatically Delete Files in Windows

Posted on October 6, 2020 By blog_786 No Comments on How to Automatically Delete Files in Windows

Earlier I wrote about the DropIt program, which automatically moves or copies files when new files appear inside a folder. This can be useful, for example, if you have limited local hard drive space and want to move all of your downloads to an external storage device.

If you want to delete files automatically, there are two ways you can do it in Windows. The first method involves downloading the free AutoDelete app that lets you set up a schedule to delete files in a specific folder. I’ve already written two detailed guides for using the program (here and here

The second way to delete files is to create a batch file and then schedule that batch file to run. All of this can be done without installing third-party software. In this article, I’ll walk you through how to create a batch file and then use the task scheduler to have the script run periodically.

Step 1 – Create a batch file

If creating a batch file sounds a little intimidating or too technical, don’t worry, because you don’t need to know what it means. I will explain what you need to copy and paste, where and what parameters you can change. First, open Notepad, copy and paste the following line of text:

forfiles -p “C: Test” -s -m *. * / D -5 / C “cmd / c del @path”

The line above probably doesn’t make sense and that’s perfectly fine as I’ll explain it below. Basically, it tells Windows to delete all files in the C: Test folder and subfolders older than 5 days. This is how your Notepad file should look like.

How to Automatically Delete Files in Windows

Before we get into more details about the command, let’s save the file and test it. First, create a folder on your computer called Test at the root of the C drive. Then click File – Save and save the file as a batch file. To do this, enter a name followed by .bat, and then change the Save as type drop-down menu to All Files.

How to Automatically Delete Files in Windows

Note that you can save the file anywhere on your hard drive, it doesn’t matter. Now create some dummy files in the Test folder and then double click the Delete.bat file to run it. Is anything being deleted? Probably not!

The reason nothing was deleted is because the command specified / D -5, which means files are older than 5 days. To delete any file no matter when it was created, you can either change -5 to -0, or you can delete the / D -5 part entirely. Now if you run it, all files will be deleted.

To customize the command, the first thing you can do is change the directory to something other than C: Test. It’s as easy as copying the path from Windows Explorer to the desired directory and pasting it into a command in Notepad.

How to Automatically Delete Files in Windows

Next comes the -s option that you see after the directory path. This means that the team must also go through all the subfolders. If you don’t want to remove files from subfolders, remove the -s parameter.

Next comes -m, followed by *. *, Which means the command must evaluate files of any type. If you only want to delete certain types of files in the folder, such as PDF files or JPG images, just change *. * To * .pdf or * .jpeg, and only these files will be deleted.

The / D -X part we already talked about in terms of how old the files need to be before they can be deleted. You can leave it with a value greater than 1, set it to 0, or remove it altogether. That’s all we need to know about the team.

There are several things to note when running this command. First, when files are deleted, they do not end up in the trash, but are deleted permanently, so be careful when using it. Second, the command only deletes files, not folders.

Since this is a batch file, you can also add multiple versions of this command to the same file. For example, here I am creating a batch file that will delete all DOCX files older than 180 days, all PDF files older than 60 days, and all TXT files regardless of the age of the files.

How to Automatically Delete Files in Windows

Step 2 – Schedule the batch file

Now that your batch file is created and saved, let’s go ahead and schedule it to run again. To do this, we need to open the task scheduler.

Luckily, I’ve already written an article on how to schedule a batch file, so open that page to get started. Scroll down to the “Schedule batch file on PC startup” section and follow the instructions.

How to Automatically Delete Files in Windows

The only thing you need to change is the trigger. You can choose from the following options: daily, weekly, monthly, at computer startup, at logon, or when a specific event is registered.

If you select something like “Weekly” or “Monthly” and click “Next”, a new screen will open where you can specify the exact time and days on which the script should run.

How to Automatically Delete Files in Windows

How to Automatically Delete Files in Windows

Hopefully this is a good solution for most people who need to perform simple automated file deletion tasks on their PCs. If you have any questions, do not hesitate to leave comments. Enjoy!

–

Share this:

  • Twitter
  • Facebook
Software Reviews

Post navigation

Previous Post: How to Remove or Uninstall Java (JRE) on Windows and Mac
Next Post: How to Rip DVDs to Your Hard Drive in Windows and OS X

Related Posts

  • Free 4 webcam monitoring apps for Android iOS
  • What Is Facebook Pay and How to Use It Software Reviews
  • MEGA Cloud Storage Review: Get Free Storage And More Software Reviews
  • The 10 Best Evernote Templates Software Reviews
  • Microsoft Teams vs Zoom, which is better now? Software Reviews
  • How To Play MKV Files On Windows Media Player Software Reviews

Leave a Reply Cancel reply

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

Archives

  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • March 2021
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • December 2019
  • July 2019
  • May 2019
  • April 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018

Categories

  • AI Tools & Guides
  • Amazon Web Services
  • Apple Watch
  • Computer Tips
  • Cool Websites
  • Featured Posts
  • Free Software Downloads
  • Gadgets
  • Gaming
  • General Software
  • Google Software/Tips
  • Hardware
  • Help Desk
  • How-To
  • iOS
  • iPad
  • iPhone
  • islamic Books
  • Linux
  • Linux Tips
  • Mac OS X
  • macOS
  • MS Office Tips
  • Networking
  • Office Tips
  • OS X
  • Product Reviews
  • Reviews
  • Safari
  • Smart Home
  • Smartphones
  • Software Reviews
  • technology
  • text
  • Tools Review
  • Troubleshooting
  • Tutorials
  • Uncategorized
  • Urdu Books PDF
  • Web Site Tips
  • Windows
  • Windows 10
  • Windows 7
  • Windows XP Tips
  • Wordpress
  • Protect Your Facebook Account From Hackers (2017)
  • 4 Ways to Share WiFi Without Giving Away Your Password
  • How to Get 2 Free Audiobooks From Audible Trial Instead of 1
  • 10 Things to Check Before Publishing a YouTube Video
  • A Simple Trick to Get 50% Discount on Audible for Three Months
DMCA.com Protection Status

Recent Posts

  • Protect Your Facebook Account From Hackers (2017)
  • 4 Ways to Share WiFi Without Giving Away Your Password
  • How to Get 2 Free Audiobooks From Audible Trial Instead of 1
  • 10 Things to Check Before Publishing a YouTube Video
  • MailTag: Real-time Email Tracking, Made Easy

Recent Comments

  1. This Simple Trick Lets You Play YouTube in the Background on iOS on YouTube Not Working? Here Are Quick Fixes To Try
  2. How to Bypass Chromecast DNS and Circumvent Geo Blocking on 5 Cool Websites to Find Good Movies and TV Shows on Netflix
  3. 5 Cool Websites to Find Good Movies and TV Shows on Netflix on check netflix video quality internet explorer
  4. SmartDNS vs VPN “What’s the Difference?” on How to Watch Apple TV on Roku
  5. How to go Back to the old YouTube Layout (2013) on 10 Things to Check Before Publishing a YouTube Video
  • How to Predict Traffic on Google Maps for Android How-To
  • The Best Add-Ons To Power Up Your Gmail Inbox Google Software/Tips
  • What Is “Sign In With Apple”, How To Use It, and How Safe It Is General Software
  • How to Fix Omegle’s “Error Connecting to Server” Issue Computer Tips
  • How to Remove Background Noise in Skype Calls How-To
  • 10 alexa tips and tricks 2022 technology
  • How to Fix Grub Rescue Error With Fixmbr Command How-To
  • How to Find Hidden Apps on iPhone 2023 iPhone

Copyright © 2023 How To Blog.

Powered by PressBook News WordPress theme

Go to mobile version