PowerShell: Tarmo Trumm,Kustutame x-päeva vanad failid: Difference between revisions
From ICO wiki
Jump to navigationJump to search
Created page with '</source> Kustutame(.laiend).ps1 <source lang="powershell"> # Skript mis kustutab mingi kindla laiendiga failid mis on x päeva vanad $Asukoht = "C:\Users\Administrator\Document…' |
No edit summary |
||
Line 1: | Line 1: | ||
Kustutame(.laiend).ps1 | Kustutame(.laiend).ps1 | ||
<source lang="powershell"> | <source lang="powershell"> |
Revision as of 17:01, 18 May 2011
Kustutame(.laiend).ps1
# Skript mis kustutab mingi kindla laiendiga failid mis on x päeva vanad
$Asukoht = "C:\Users\Administrator\Documents" #Failide asukoht
$P2evavana = "-1" #Mitu päeva vanad failid(- peab ette jääma)
$Laiend = "*.torrent" #Mis laiendit tahad kustutada
$T2nanep2ev = Get-Date
$DatetoDelete = $T2nanep2ev.AddDays($P2evavana)
$Files = Get-ChildItem $Asukoht -include $Laiend -recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } |
#Teavitame kasutajat millised failid kustutatakse
ForEach-Object {Write-Host Kustutamisele fail $_.name -foregroundcolor red}
#Küsime kasutajalt kas ta tahab ikka need failid kustutada
$continue = Read-Host -Prompt "Kas oled nõus need failid kustutama? (jah / ei)";
switch($continue ){
"jah" {Get-ChildItem $Asukoht -include $Laiend -recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } |Remove-Item}
default {out-null}
}