Jump to content

Recursively organize files?


Recommended Posts

Posted (edited)

Is there a CMD command or batch file in Windows that would allow me to recursively move, say, all files named "*-trailer.mkv" in my movies folders to "Trailers" subfolders in each of those folders and rename them "Theatrical Trailer.mkv"?

 

I've googled the heck out of this but I can't figure out how to do it. I'm trying to make reorgainzing my extras easier on myself.

Edited by chyron8472
Happy2Play
Posted

Any reason why?

Deathsquirrel
Posted (edited)

Trailers aren't like other extras, they typically live in the same folder as the movie.  For example:

 

\Monty Python and the Holy Grail (1975)

\Monty Python and the Holy Grail (1975)\Monty Python and the Holy Grail (1975).mkv

\Monty Python and the Holy Grail (1975)\Monty Python and the Holy Grail (1975)-trailer.mkv

Monty Python and the Holy Grail (1975)\Extras\Monty Python and the Holy Grail in Lego.mkv

Edited by Deathsquirrel
naeonline
Posted

This is a long-handed version in a powershell script.  I attached it as a text file, just rename the extension from .txt to .ps1
I haven't tested it so it may be wise to copy a few movies/trailers to a temp directory and run it against that first.

#  <--These are comments in powershell
#Set the root folder where your movies reside. Can be a network path as well
$MovieRoot = "N:\MyMedia\Movies"
            #  ^^^^^^^Change this to your movies folder
            
#Get a recursive list of all trailer files
$TrailerList = Get-ChildItem -Path $MovieRoot -Include "*-trailer.mkv" -File -Recurse -Force
#Loop through the list of trailer files and process each one
ForEach ( $TrailerFile In $TrailerList ) {
    #Check to see if trailer already in "Trailers" folder
    If ( $TrailerFile.DirectoryName -notlike "Trailers" ) {
        #Check to see if a "Trailers" folder exists
        If ( !(Test-Path -LiteralPath "$($TrailerFile.Directory)\Trailers" -ErrorAction SilentlyContinue) ) {
            #Create a new trailers folder since one didn't exist
            New-Item -ItemType Directory -LiteralPath "$($TrailerFile.Directory)\Trailers" -Force
        }
        #Move the trailer into the "Trailers" folder while renaming it to "Theatrical Trailer"
        Move-Item -LiteralPath $TrailerFile -Destination "$($TrailerFile.Directory)\Trailers\Theatrical Trailer.$($TrailerFile.Extension)" -Force
    }
    #It is already in a "Trailers" folder but named like *-trailer not "Theatrical Trailer"
    Else {
        #Rename the file to "Theatrical Trailer"
        Move-Item -LiteralPath $TrailerFile -Destination "$($TrailerFile.Directory)\Theatrical Trailer.$($TrailerFile.Extension)" -Force
    }
}

MoveTrailers.txt

Happy2Play
Posted

They can be either way,

 

Trailers Wiki

 

I tested Moviename\trailers\theatrical trailer.ext naming scheme appears to work also.

Posted

I don't know. When I was reorganizing my extras after starting to use Plex, I noticed many a trailer that showed up as its own movie for some reason.

 

I'm planning on putting Emby on my dad's server, and I'm not looking forward to renaming all his extras manually as well.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...