File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change
1
+ $limit = (Get-Date ).AddDays(-7 )
2
+ $path = " <DirectoryWhereFilesNeedToBeDeleted>"
3
+ Get-ChildItem - Path $path - Recurse - Force | Where-Object { ! $_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item - Force - WhatIf
4
+
5
+
6
+
7
+
8
+ # -7 Means delete files older than 7 days.
9
+ # $path is the path of the directory where you'd like to delete the files
10
+ # -Recurse can be removed in order to not recurse in directories
11
+ # -WhatIf Means that you are only testing the deletion. To check for any errors. Remove this option to actually delete the files
12
+
13
+ # The advantage is that deleting over 100.000 files in a directory using the Windows Explorer, is terribly slow!
14
+
15
+ Shorter version in a oneliner:
16
+ # Get-ChildItem -path <DirectoryWhereFilesNeedToBeDeleted> | where {$_.Lastwritetime -lt (date).adddays(-7)} | remove-item
You can’t perform that action at this time.
0 commit comments