The Complete Guide to Scripting with DelAge Command Line

Written by

in

How to Use DelAge for Automated File Deletion Managing storage space on your servers or local machines often requires clearing out old, obsolete logs, backups, or temporary files. Doing this manually is time-consuming and prone to human error. DelAge is a lightweight, command-line utility for Windows designed specifically to automate the deletion of files based on their age.

Here is a comprehensive guide on how to download, configure, and automate file deletion using DelAge. What is DelAge?

DelAge is a free, standalone command-line tool that scans specified directories and deletes or moves files that are older than a set number of days. Unlike native Windows batch commands which can be complex to write for date calculations, DelAge simplifies the process into a single line of code. Key capabilities include:

Filtering files by creation, modification, or last-accessed dates. Recurse through subdirectories.

Moving old files to an archive directory instead of deleting them.

Using wildcards to target specific file extensions (e.g., .log). Basic Command Syntax The general structure of a DelAge command is as follows: delage32.exe [file_mask] [age] [options]

file_mask: The path and type of files you want to target (e.g., C:\Logs*.log).

age: The minimum age of the files in days (e.g., 30 for files older than 30 days).

options: Switches that modify how the tool behaves (e.g., /sub for subdirectories). Common DelAge Switches and Options

To customize your automated deletion, you will use various command-line switches:

/sub: Includes all subdirectories within the specified path.

/created: Bases the age calculation on the file’s creation date.

/accessed: Bases the age calculation on the date the file was last opened.

/modified: Bases the age calculation on the date the file was last changed (this is the default behavior if no date switch is specified).

/rd: Removes empty directories after the files inside them are deleted.

/move [path]: Moves the old files to a designated directory instead of deleting them permanently.

/preview: Simulates the command execution. It displays what would be deleted without actually removing any files. Always use this first. Step-by-Step Implementation Examples Example 1: Deleting Log Files Older Than 14 Days

To delete all .log files in C:\AppLogs that have not been modified in the last 14 days, use this command: delage32.exe “C:\AppLogs*.log” 14 Example 2: Cleaning Subdirectories and Empty Folders

To delete files older than 60 days across all subfolders, and clean up any folders left completely empty by the deletion: delage32.exe “D:\Backups*.” 60 /sub /rd Example 3: Archiving Instead of Deleting

If you prefer to archive files older than 90 days to an external storage drive rather than deleting them permanently: delage32.exe “C:\Data*.*” 90 /move “E:\Archive\” Automating DelAge with Windows Task Scheduler

To make this process truly hands-off, you can schedule the DelAge command to run automatically at specific intervals using the native Windows Task Scheduler. Step 1: Create a Batch File Open Notepad.

Type your exact DelAge command. Ensure you use absolute paths for both the delage32.exe executable and your target folders. Example: “C:\Tools\delage32.exe” “C:\Logs*.log” 30 /sub

Save the file with a .bat extension, such as clean_logs.bat. Step 2: Set Up the Scheduled Task

Press the Windows Key, type Task Scheduler, and press Enter. Click Create Basic Task in the Actions panel on the right.

Name your task (e.g., “Monthly Log Cleanup”) and click Next.

Choose your desired frequency (Daily, Weekly, or Monthly) and click Next. Set the start time and recurrence pattern, then click Next. For the Action, select Start a program and click Next.

Click Browse, select the clean_logs.bat file you created in Step 1, and click Next. Click Finish to save the task. Best Practices and Safety Tips

Test with /preview First: Before running a new script or setting up a scheduled task, always append the /preview switch to your command. This allows you to verify that your file mask and age criteria are correct without risking accidental data loss.

Use Quotes for Paths: Always enclose your file paths in double quotes (e.g., “C:\Program Files\My App*.tmp”). This ensures the command line interprets paths containing spaces correctly.

Monitor System Permissions: Ensure that the user account running the Windows Task Scheduled job has explicit “Read”, “Write”, and “Delete” permissions for the target directories. If it lacks these permissions, the script will silently fail. If you want to fine-tune your script, tell me: What operating system version are you running? What specific file extensions do you need to delete? Do you need to keep a log of what gets deleted?

I can provide the exact script syntax optimized for your environment.

Comments

Leave a Reply

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