Created
December 21, 2018 09:04
-
-
Save autinerd/796e01c493e835369c13849a05ce0923 to your computer and use it in GitHub Desktop.
Moves all files from "recup_*" folders from Photorec into folders named by the extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$root = '/' | |
Set-Location -Path $root | |
$a = $(Get-ChildItem | Where-Object {$_.Name -like 'recup*'}) | |
$totalfiles = 0 | |
$filecount = 0 | |
foreach ($folder in $a) { | |
$totalfiles += $(Get-ChildItem $folder).Count | |
} | |
foreach ($folder in $a) { | |
$files = Get-ChildItem $folder | |
foreach ($file in $files) { | |
$filecount++ | |
Write-Output ("Datei {0} von {1} wird verschoben..." -f $filecount,$totalfiles) | |
$destinationDir = Join-Path -Path $root -ChildPath $file.Extension.Replace('.', '') | |
if (-not (Test-Path -Path $destinationDir)) { | |
New-Item -Path $destinationDir -ItemType Directory | Out-Null | |
} | |
Move-Item -Path $file -Destination $destinationDir | |
} | |
Remove-Item $folder | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment