PowerShell: Tarmo Trumm,Kustutame x-päeva vanad failid

From ICO wiki
Revision as of 17:01, 18 May 2011 by Ttrumm (talk | contribs) (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…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

</source> 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}
}