Skip to content

Instantly share code, notes, and snippets.

@Gunslap
Created February 2, 2022 17:24
Show Gist options
  • Save Gunslap/0473b530cb931977f98612234255ec87 to your computer and use it in GitHub Desktop.
Save Gunslap/0473b530cb931977f98612234255ec87 to your computer and use it in GitHub Desktop.
Move All Files in a Folder to Subfolders (Handy for Radarr Movies)
$path = "V:\_Movies" #Path to scan
#Grab all files + folders in that path
$childItems = Get-ChildItem -Path $path -Force
#Loop through the child items
foreach($item in $childItems)
{
#filter out directories
if($item.PSIsContainer -eq $false)
{
$item.name
$folderName = $item.name.Substring(0,$item.name.length - $item.Extension.Length)
#Make a folder with the same name as the current file
New-Item -Path "$path\$folderName" -ItemType Directory -ErrorAction Ignore
#Move the file into the folder
Move-Item -LiteralPath $item.FullName -Destination "$path\$folderName\$item"
}
}
@Gunslap
Copy link
Author

Gunslap commented Feb 2, 2022

As long as subtitle files have the exact same name as the movie file (assuming that what you're using this for), it should be moved into the same directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment