Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanderwijk authored Mar 5, 2020
0 parents commit 45391d3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions RemoveALargeNumberOfFilesInDirectory.ps1
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

0 comments on commit 45391d3

Please sign in to comment.