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===================================================================================================================
Rem AUTHOR: SHIVAM KUMAR | https://www.linkedin.com/in/shivamkumars
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.
Rem===================================================================================================================

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"
)
)
EXIT /B 0

Comments

Popular posts from this blog

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

Adding Home Older Newer Post Buttons in new Blogger templates such as Contempo

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