Script to delete the files older then 2 days from All Available Drives On Servers:\AnyDirectory

  • Script below can be used to delete the files which are older then 2 days from All Available Drives On Servers:\AnyDirectory.
  • If you want to filter files with some particular extension please add the following handle to the script :
  • /m (searchmask) Searches files according to the specified search mask. The default search mask is *.\*.
  • More information about parameters and variables available can be found here
@ECHO off
Rem VERSION: 1.0
Rem DESCRIPTION: Script to delete the files which are older then 2 days from "All_Available_Drives_On_Servers:\AnyDirectory" directory
Rem How to use: Select the servers from hpsa and right click and run script,no user input is required.
Rem Disclaimer: The script has to be run on proper timings after the backup or what ever patching activity else you might loose data.

for /F "skip=1" %%Y in ('wmic Logicaldisk get caption') do  (
    for /F %%G in ("%%Y") do ( 
forfiles.exe /p %%G\AnyDirectory\ /m * /d -2 /c "cmd /c if @isdir==TRUE rmdir /Q @path /S"


Popular posts from this blog

Enabling fixed Sidebar for blogger Contempo template for screen sizes smaller than 1440px

Adding copy to clipboard button to every google code prettify pre blocks in blogger

Solution: More Posts & Posts Links not working with Adsense Anchor ads on Touch screen mobiles in blogger

Query to Expand and List All logins within a SQL Server Group

Powershell script to automatically send HTML emails using gmail smtp

Adding code prettify to Blogger