-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 45391d3
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$limit = (Get-Date).AddDays(-7) | ||
$path = "<DirectoryWhereFilesNeedToBeDeleted>" | ||
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force -WhatIf | ||
|
||
|
||
|
||
|
||
# -7 Means delete files older than 7 days. | ||
# $path is the path of the directory where you'd like to delete the files | ||
# -Recurse can be removed in order to not recurse in directories | ||
# -WhatIf Means that you are only testing the deletion. To check for any errors. Remove this option to actually delete the files | ||
|
||
# The advantage is that deleting over 100.000 files in a directory using the Windows Explorer, is terribly slow! | ||
|
||
Shorter version in a oneliner: | ||
# Get-ChildItem -path <DirectoryWhereFilesNeedToBeDeleted> | where {$_.Lastwritetime -lt (date).adddays(-7)} | remove-item |