Skip to content

Commit 45391d3

Browse files
Add files via upload
0 parents  commit 45391d3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

0 commit comments

Comments
 (0)