Skip to content

Instantly share code, notes, and snippets.

@autinerd
Created December 21, 2018 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autinerd/796e01c493e835369c13849a05ce0923 to your computer and use it in GitHub Desktop.
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
$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