-1

I have an interesting problem. I need to delete directories that are older than x days but are only numerical. We have a log folder that has log files that we need to delete but other files and folders are also stored in the same locatin.. Normally i would do PS scripts to delete all directories over x amount of days but i can delete all folders. I only need to delete folders that are fully numeric.

Wanted to see if anyone had any ideas?

4
  • 1
    What's the general format of the folder name you want to delete?
    – GregL
    Mar 23, 2015 at 16:17
  • Your question does not make sense / is not consistent. For example, it is not clear if you are deleting files or folders, and the 2nd to last sentence makes no sense. You also never actually ask a a question. Please edit to clarify your intent and ask a proper question.
    – dbenham
    Mar 23, 2015 at 17:11
  • Fully numeric? $_.Name -notmatch "\D"? Mar 23, 2015 at 17:12
  • sorry, I am deleting folders.
    – michael B
    Mar 23, 2015 at 18:07

1 Answer 1

0

$root = 'C:\logs'

Get-ChildItem -Path $root | Where-Object { $.name -match "^\d*$" -and $.LastWriteTime -lt (Get-Date).Adddays(-45) } | Remove-Item -Recurse -Force

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .