How to Delete Files Older Than Max Age

How to make a basic script to purge files older than a particular age in days? How to Change the sRoot and nMaxFileAge variables? And I want to run the script periodically, save it to a location like C:\\Scripts\\purge_old_files.vbs, and create a scheduled task with a Run setting; what should I do?

Best Answered by

Jaden· Answered on Mar 22, 2024

To achieve this, you can use the option to create a primary task, select "Start a program" as the action with the script as the path - Program//script and //B C:\\Scripts\\purge_old_files.vbs in the Add Arguments or optional field. You can run this on a File Server, log in as local admin and even have domain admin permissions.

To find the specific script, you can check them on the Microsoft website to learn about the scripts for deleting files.

Besides the scripts, you can also use the Command Prompt on Windows to set up a deletion schedule. The Command Prompt is a versatile tool that may be used for various tasks. You can, for example, utilize it to change system settings or run other apps.

And the Command Prompt on Windows can also assist you in removing files. So, here's how you may use this tool to erase your old files:

  • In the Start menu search bar, type Command Prompt.
  • Select Run as administrator by right-clicking on the Best match result.
  • Enter the following code: ForFiles //p "C:\\Target_Folder" //s //d -Number_of_Days //c "cmd //c del @file"
  • Replace the C:\\Target_Folder with the correct folder path. Then, enter the number of days since the files were last updated in the Number of Days command.

So, you can now choose which files to delete. Assume you select files that were last edited 14 days ago. Here's what your command should look like with the information you currently have:

ForFiles //p "C:\\Users\\tladi\\Downloads" //s //d -14 //c "cmd //c del @file"

However, You should understand that using cmd to remove files is not the same as emptying the Windows Recycle Bin. You can retrieve data from the Recycle Bin folder directly. However, recovering cmd deleted files is difficult without data recovery tools. With EaseUS Data Recovery Wizard, you can rapidly recover these essential items.

Use EaseUS Data Recovery Wizard to recover deleted or lost files easily and quickly.

Tutorials on how to recover lost, deleted, or formatted data from HDD, SSD, USB, SD card, or other storage media on Windows and Mac.

People Also Ask

Do Delete Files from SD Card Go to Recycle Bin on Windows

Do delete files from SD card go to Recycle Bin? After deleting some files from your SD card, you can't find the deleted files in Recycle Bin. If you want to know where the deleted files from the SD card go, this article will tell you the answer.

Brithny

Mar 19, 2024

How to Fix Windows 8.1 System Files Not Accessible on Computer

It looks like your system files are deleted or corrupted. Don't be frustrated. Since you can open CMD, you can fix the problem with the CMD. We will show you how to do that.

Dany

Mar 20, 2024

How to Recover Deleted/Unsaved Smart Notebook Files [Windows Tips]

It's typical on the internet for people to desire to get their hands on Smart Notebook files. You should read this article if your smart notebook has ceased functioning or if you have lost the data on it.

Jaden

Mar 20, 2024

Deleted My Partitions by Mistake While Installing Windows 7

Before installing Windows 7 on your computer, you should back up your data. If you don't have a backup, you can recover data from the HDD which lost partitions with EaseUS Data Recovery Wizard.

Dany

Apr 15, 2024

Can I Recover Permanently Deleted Files Without Previous Versions

Can I recover permanently deleted files without previous versions? Don't worry if you don't have the previous version of your deleted files. This article will introduce effective ways to recover permanently deleted files without previous versions.

Brithny

Mar 25, 2024

How to Delete the OS from a Hard Drive but Keep the Data

Let us now look at removing Windows OS from a hard drive with retaining the data. In other words, without formatting it. It's also the methods of how to remove and uninstall Windows 7, 8, or 10 from a dual boot PC.

Jaden

Apr 10, 2024