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
| $files = Get-ChildItem *.txt | Where-Object { !$_.PSIsContainer }
foreach($file in $files)
{
$content = Get-Content $file
$destination = ""
if ($content -like "*GLS*")
{
$destination = "GLS"
}
elseif ($content -like "*TNT*")
{
$destination = "TNT"
}
else
{
continue
}
# Prévoir la création des dossiers si il n'existe pas
if (!(Test-Path -Path $destination))
{
New-Item -Path $destination -ItemType directory
}
$file | Move-Item -Destination ($destination + "\" + $file.Name)
} |