Skip to content

Instantly share code, notes, and snippets.

@arieffikhrie
Created August 10, 2020 13:31
Show Gist options
  • Save arieffikhrie/32d3a8a7fdf121cf102ca35890ac898c to your computer and use it in GitHub Desktop.
Save arieffikhrie/32d3a8a7fdf121cf102ca35890ac898c to your computer and use it in GitHub Desktop.
Sorting animes
$path = (Get-Location).Path
$FileExtension = ".mkv";
$list = Get-ChildItem -Path $path -File | Where-Object {$_.extension -eq $FileExtension}
foreach ($file in $list) {
$filename = $file.name -replace "\[.*?\]", ""
$filename = ($filename -replace $FileExtension, "").Trim()
$filename2 = $filename -Split "-"
$filename3 = $filename2[0..($filename2.length - 2)]
$foldername = ($filename3 -join "-").Trim()
$folderPath = Join-Path -Path $path -ChildPath $foldername;
if (-not(Test-Path $folderPath)) {
New-Item -Path $folderPath -ItemType "directory"
}
Move-Item -LiteralPath $file.FullName -Destination (Join-Path $folderPath -ChildPath $file.name) -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment