Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Created July 8, 2020 19:08
Show Gist options
  • Save TylerLeonhardt/d7d674864e2dffc17802f89172f853d6 to your computer and use it in GitHub Desktop.
Save TylerLeonhardt/d7d674864e2dffc17802f89172f853d6 to your computer and use it in GitHub Desktop.
A script I used to organize videos
#param(
$RootPath = "/Users/tyleonha/Desktop/SurvivorDays"
#)
$movies = Get-ChildItem $RootPath -File
$folders = [System.Collections.Generic.List[string]]@(
"placeholder since index 0 is the 'new folder' option"
)
$title = "Choice prompt"
$whichFolder = "Which folder would you like to put this in?"
$options = [System.Collections.Generic.List[System.Management.Automation.Host.ChoiceDescription]]@(
[System.Management.Automation.Host.ChoiceDescription]::new("New", "Create a new folder.")
)
Get-ChildItem $RootPath -Directory | ForEach-Object {
$folders.Add($_.FullName)
$options.Add([System.Management.Automation.Host.ChoiceDescription]::new("&$([char](64 + $options.Count))" + $_.Name, $_.FullName))
}
foreach ($movie in $movies) {
Invoke-Item $movie
$response = $host.UI.PromptForChoice($title, $whichFolder, $options, 0)
if ($response -eq 0) {
$folderName = Read-Host -Prompt "What is the new folder name?"
$folder = New-Item -Path (Join-Path $rootPath $folderName) -ItemType Directory
$folders.Add($folder.FullName)
$options.Add(
[System.Management.Automation.Host.ChoiceDescription]::new("&$([char](64 + $options.Count))" + $folder.Name, $folder.FullName)
)
$destination = $folder.FullName
} else {
$destination = Get-Item $folders[$response]
}
$title = Read-Host -Prompt "What do you want to call this video?"
if ($title -notlike "*$($movie.Extension)") {
$title += $movie.Extension
}
Move-Item -Path $movie.FullName -Destination (Join-Path $destination $title)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment