batch/scripts file fro deleting files older than X days


hi,

 

can 1 provide me bath/script file deleting files under directory , subdirectory without deleting directories.files older 7 days.

i need because trying automate logs rotation manual work reduced.

 

any woud appreciated.!!

thanks in advance.


savio

savio,

i think kazun has answered this.  in powershell dir command alias get-childitem.  d:\files needs changed starting directory logs are.  "-for" force , "-rec" recurse subdirectorires.  "?" "where-object" alias checking 7 day old/older files are not (the "!") containers (not directories).  directories skipped recursed into.  if current file in pipe makes far through checks forcefully deleted.  in powershell del alias remove-item.  "$_" variable current file being checked in pipe.

here kazun's code rewritten long hand without aliases example ......

get-childitem  c:\websphere\applogs  -force -recurse | where-object {$_.lastwritetime -le (get-date).adddays(-7) -and !$_.psiscontainer} | remove-item -force

dir alias not use same switches old dos dir command.  uses switches of powershell  get-childitem command.  confused me when first started in powershell.

get-help get-childitem

michael



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file