1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| $Source='C:\Temp\Test\'
$Destination='C:\Temp\Test\Tri'
$i=1
$j=0
Get-ChildItem $Source -include *.html,*.txt,*.riff,*.swf,*.gz,*.xml,*.h,*.swc,*.java,*.gif,*.exe,*.ogg,*.sqlite,*.png,*.dll,*.mui,*.cp_,*.plist,*.wmf,*.ttf,*.iec -Recurse | Remove-Item -Verbose
$j=(Get-ChildItem | Sort-Object -Property extension | Group-Object -Property extension | Measure-Object -Line).lines
Do{
$grp=Get-ChildItem $Source -File | Group-Object -Property Extension
$grp[0].Name
$grp[0].Group
$NewDirectory="$Destination\$($grp[0].Name)"
if(Test-Path -Path $NewDirectory)
{
Write-Host "* Dossier déjà existant" -ForegroundColor Red
}
else
{
Write-Host "* Dossier à créer" -ForegroundColor Red
MD $NewDirectory
}
#$grp[0].Group | Copy-Item -Destination $NewDirectory -WhatIf
$grp[0].Group | Move-Item -Destination $NewDirectory -Verbose
$i++
} While ($i -le $j)
Get-ChildItem $Source -File |
Group-Object -Property Extension |
Foreach {
$_|
Foreach {
Write-verbose "Copie les fichiers d'extension '$($_.Name)'"
}
} |
Partager