Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell version #1

Open
therealmichaelberna opened this issue Sep 3, 2021 · 0 comments
Open

Powershell version #1

therealmichaelberna opened this issue Sep 3, 2021 · 0 comments

Comments

@therealmichaelberna
Copy link

therealmichaelberna commented Sep 3, 2021

Here's a powershell version that I made that if they are named properly it will add the season and episode, so I wanted to share. Please note, for it to work, the column names must be single words renamed to "Number" "Name" "Aired"

cls
#$CSVPath = Read-Host "Please enter CSV path"
#$directory = Read-Host "Please enter directory path"
$directory = "Z:\Television\Looney Tunes"
cd $directory

$CSVPath = "Z:\Television\Looney Tunes\tvdb.csv"    
"CSV Path: $CSVPath"

$csv = Import-CSV $CSVPath
#$csv | Select-Object Number, Name, Aired | Format-Table

$csv | ForEach-Object{

    $name = $($_.Name)
    $number = $($_.Number)

    Get-ChildItem *$name*|%{
        "Match found for $name"
        "$name info:"
        "number: $number"        

        $pos = $number.IndexOf("x ")
        $episode = [int]$number.Substring($pos+2)
        
        if($episode -lt 10)
        {
            $episode = "0$episode"
        }

        "Episode: $episode"
         
        $fullName = $($_.FullName) 

        "childItemName:  $fullName"
        $containingFolder = Split-Path -Path $fullName
        "Containing Folder: $containingFolder"
        $fileName = Split-Path -Path $fullName -Leaf -Resolve

        "Filename: $fileName"

        $season = $number.substring(0, 4)
        "Season: $season"
        
        $preparedStatement = [Regex]::Escape("Looney Tunes - ")
        $newFileName = $fileName.replace("Looney Tunes - ", "Looney Tunes - "+"s$season"+"e$episode - ")        

        $destFile = $containingFolder + "\Season $season\$newFileName"

        "Dest: $destFile"
        $destFolder = Split-Path -Path $destFile
        "Dest folder: $destFolder"
        
        If(!(test-path $destFolder))
        {
              New-Item -ItemType Directory -Force -Path $destFolder
        }

        Move-Item -Path $fullName -Destination $destFile
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant