Files that are younger than the date can be deleted via the command line!
It is quite easy to delete files that are younger than a certain date via the command line under Windows 11, 10, ... and MS Server OS!
Everyone probably knows the function: ►► delete the temporary files older than X days under Windows 11 or 10, but you also have to clean up other folders under Windows based on the date as long as the date and time have not been manipulated, this is also very easy under Windows!
forfiles -p "C:\What\ever\folder" -s -m *.* /d -<count of days> /C "cmd /c del @path"
Very simple, so /d -2 is two days
Parameters in forfiles
Microsoft Windows [version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Nenad>forfiles /?
FORFILES [/ P path name] [/ M search mask] [/ S]
[/ C command] [/ D [+ | -] {dd.MM.yyyy | TT}]
Description:
Selects a file (or set of files) and executes a
command on that file. This is useful for batch jobs.
Parameter list: /P pathname Specifies the path on which the search is started
. The default
folder is the currently used folder (.).
/M Search mask Searches for files according to a search mask.
The standard search mask is "*".
/S Searches subdirectories
recursively, such as B. "DIR / S".
/C command Specifies the command to be executed for each file.
Command strings should be
enclosed in double quotation marks.
The standard command is "cmd / c echo @file".
The following variables can be used in the
command
string : @file - Displays the name of the file.
@fname - Displays the filename without the
extension.
@ext - Displays the
file extension only .
@path - Displays the full file path.
@relpath - Displays the relative
file path.
@isdir - Displays "TRUE" if a file type is one
Directory is and "FALSE" for files.
@fsize - Displays the file size in bytes
.
@fdate - Displays the last modification date of
the file.
@ftime - Displays the last modification time of the
file.
Use hexadecimal
code for characters in the format 0xHH to include special characters on the
command line (e.g. 0x09 for
tab stop). Internal commands for cmd.exe
should follow "cmd / c".
/D date Selects files with a modification date greater than
or equal to (+), or less than or equal to
(-), the specified date with the format
"dd.MM.yyyy"; or select files whose last
modification date is greater than or equal to (+) the
Today's date plus "dd" days or or less
or equal to (-) today minus "dd" days. Valid
values for "tt" are numbers between 0 and 32768. If
not specified, "+" is
used by default .
/? Displays this help.
Examples:
FORFILES /?
FORFILES
FORFILES / PC: \ WINDOWS / S / M DNS *. *
FORFILES / S / M * .txt / C "cmd / c type @file | more"
FORFILES / PC: \ / S / M * .bat
FORFILES / D -30 / M * .exe
/ C "cmd / c echo @path 0x09 was changed 30 days ago"
FORFILES / D 01.01.2001
/ C "cmd / c echo @fname is new since 01.01.2001"
FORFILES / D + 19.1.2021 / C "
FORFILES / S / M * .doc / C "cmd / c echo @fsize"
FORFILES / M * .txt / C "cmd / c if @ isdir == FALSE notepad.exe @file"
C: \ Users \ Nenad>
2.) Delete files that are older than X days with PowerShell!
Here is an example to clean up the download folder in such a way that all files that are older than 30 days are deleted!
It is easy to rename files in batches using a script or command prompt in lower and / or upper-case letters on Windows 11, 10, and MS Server OS Everyone
This website does not store personal data. However, third-party providers are used to display ads, which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF). The CMP ID is 300 and can be individually customized at the bottom of the page. more Infos & Privacy Policy ....