Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Faq ► FAQ - Command Prompt - Windows 11, 10, etc. ► ««« »»»

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!  



Contents:
1.) ... Example: Remove files that are older than 1 day!
2.) ... Delete files that are older than X days with PowerShell!
3.) ... More tips for deleting under Windows via command line and without!




1.) Example: Remove files that are older than 1 day!

This will delete all files (*.*) In the folder with all subfolders that

are older than 1 day (/d -1)


forfiles /p "C:\Folder1\Subfolder" /s /m *.* /c "cmd /c Del @path" /d -1


So: 

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!  


Get-ChildItem "%userprofile%\Downloads" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))}| Remove-Item



3.) More tips for deleting under Windows via command line and without!


►► Delete complete directories with PowerShell and CMD, with examples?
►► Command line to delete the temporary files on Windows drives!
►► Search data, sort by date and delete when restarting! 





FAQ 105: Updated on: 26 August 2023 10:52 Windows
Windows-Console

Waiting for keyboard input Command prompt Script?


Often you want to stop the script in the batch file and wait for the user to press Enter, or variables to process on Windows 11, 10, and MS Server OS
Windows-Console

Delete all files except the most recent via command line, script or CMD.EXE?


It is easy to delete all files except the most recent via command line, script or CMD.EXE for Windows 11, 10, and MS Server The most popular script
Windows-Console

Ability to batch rename files in lower and upper case?


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
Windows-Console

Serial number of the hard disk under Windows 11, 10, ... via command prompt!


It is quite easy to find out the serial number of your hard disk under Windows 11, 10, or MS Server 2022, at a command prompt There are free hard
Windows-Console

Find out the PC serial number and manufacturer via command prompt?


Using the command prompt, it is easy to find out the PC serial number and manufacturer under Windows 11, 10, and MS Server OS Everyone has ► read out
Windows-Console

Lock the PC via the command prompt, Windows 11, 10, ...!


Locking Windows 11, 10, or MS Server 2022, 2019, is also possible via the command prompt It is not the fastest way to lock your Windows 11, 10,
Windows-Console

Share more fonts for Windows 11, 10, ... command prompt!


It is easy to give more fonts for Windows 11, 10, command prompt Everyone has ► changed the color, font, etc. for the command prompt / CMD  may

»»

  My question is not there in the FAQ
Asked questions on this answer:
Keywords: windows, 11, 10, console, files, that, younger, than, date, deleted, command, line, quite, easy, delete, certain, time, Questions, Answers, Software




  

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks
  + Security

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK


  + Freeware
  + DesktopDigitalClock
  + ClassicDesktopClock
  + PreventTurnOff
  + QuickMemoryTestOK
  + IsMyHdOK
  + AutoPowerOptionsOK
  + OneLoupe
  + TraceRouteOK
  + GetWindowText
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Settings | Windows 10 | gc24b | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2025 by Nenad Hrg softwareok.de • softwareok.com • softwareok.com • softwareok.eu


► Up Down Rename The next File or Folder! ◄
► Hide mouse cursor in Desktop OK! ◄
► Terminate APPs, applications on Windows 11, 10, ...! ◄
► Gif animations in the Quad Explorer on MS Windows 11, 10, ... OS! ◄


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

....