Created
August 10, 2020 13:31
-
-
Save arieffikhrie/32d3a8a7fdf121cf102ca35890ac898c to your computer and use it in GitHub Desktop.
Sorting animes
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
$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