Reputation: 53
I would like to remove specific text files from my folder (D:\Test) using powershell script. Below are the list of files i have in my folder and need to remove files with name "Defrag" in the file name.
I need to remove the files with name "Defrag".
Thanks for your help in advance.
Pratap
Upvotes: 4
Views: 16862
Reputation: 1774
How about Get-ChildItem * -Include *Defrag* -Recurse | Remove-Item
from Delete File in Subfolders Recursively by Microsoft?
Upvotes: 0
Reputation: 7465
PowerShell is really powerful. This one can be done with one line:
Remove-Item -Path "pathtoyourfile\*Defrag*.txt"
And to your second question:
Get-ChildItem -Path "pathtoyourfile\*Defrag*.txt" -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt (Get-Date).AddDays(-15) } | Remove-Item -Force
Upvotes: 11