Batch program to move files to separate folders

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
jtap06 Offline
Senior Member
Posts: 233
Joined: Jan 2009
Reputation: 0
Location: Chicago, IL
Post: #1
Tried a search but nothing came up. Looking for a batch script that will move all of a film's .avi/.mkv, .tbn, .nfo, etc. into a separate folder. I am sure you guys know what I mean.

Thanks!
find quote
FernFerret Offline
Senior Member
Posts: 240
Joined: Mar 2009
Reputation: 0
Location: Indiana, USA
Post: #2
If you're using windows: This is what I use:
http://www.thehtpc.net/files/file2folder.rar

Article here: http://www.thehtpc.net/?s=rename

Only catch is, that cd1 and cd2 will be moved to different folders, simply find, move and remove empty folders, presto.
(This post was last modified: 2009-04-30 09:37 by FernFerret.)
find quote
Montellese Online
Team-XBMC Developer
Posts: 3,620
Joined: Jan 2009
Reputation: 34
Location: Switzerland
Post: #3
Exactly what I was looking for as well :-)
I was about to write my own one but didn't find any time to do it.
find quote
jtap06 Offline
Senior Member
Posts: 233
Joined: Jan 2009
Reputation: 0
Location: Chicago, IL
Post: #4
Awesome! Thanks a lot FernFerret. Just what I needed. You wouldn't happen to know the code to have it so that -fanart will also be placed in the new folders as well would you? Or if anyone else knows? Thanks though. You saved me a lot of clicky clicks! Smile
find quote
Montellese Online
Team-XBMC Developer
Posts: 3,620
Joined: Jan 2009
Reputation: 34
Location: Switzerland
Post: #5
Well I think I'll end up writing my own program nonetheless which will move all the NFOs, fanarts, tbn, trailers etc to a new folder and rename the files.

This batch script only moves the files to new folders leaving me with all my additional files in the original place.
find quote
Hitcher Offline
Skilled Skinner
Posts: 10,627
Joined: Aug 2007
Reputation: 91
Location: Eastleigh, UK
Post: #6
I'm sure fekker made one ages ago that I used at the time to transfer over to folders.
find quote
Nmarconi Offline
Aeon Group
Posts: 77
Joined: Oct 2008
Location: Boston
Post: #7
Montellese Wrote:Well I think I'll end up writing my own program nonetheless which will move all the NFOs, fanarts, tbn, trailers etc to a new folder and rename the files.

This batch script only moves the files to new folders leaving me with all my additional files in the original place.

If you are on windows - i have a .net program that i threw together that can move the nfo,fanart,tbn and rename them. I need to polish it up. Ill post a link tonight around 9pm EST.
find quote
jtap06 Offline
Senior Member
Posts: 233
Joined: Jan 2009
Reputation: 0
Location: Chicago, IL
Post: #8
Thanks Nmarconi! I'll definitely use it. 2,000+ collection. Sad
find quote
david81 Offline
Senior Member
Posts: 155
Joined: Dec 2008
Reputation: 0
Post: #9
http://forum.xbmc.org/showpost.php?p=256...stcount=68
find quote
Hitcher Offline
Skilled Skinner
Posts: 10,627
Joined: Aug 2007
Reputation: 91
Location: Eastleigh, UK
Post: #10
david81 Wrote:http://forum.xbmc.org/showpost.php?p=256...stcount=68

Blimey, how'd you manage to find that?
find quote
AnalogKid Offline
Fan
Posts: 648
Joined: Feb 2009
Reputation: 141
Post: #11
OK... this batch file will also move your flat files into their own folders...

NOTE: the command will COPY file to subfolders (just for safety). If you prefer to move, then rename the COPY command to MOVE

It will work for your movies, thumbs, fanart and fix the CD1 issue i.e. it WILL work with multipart movies.

To use... drop your Movies folder onto the batchfile below... that's it!



@echo off
set SourceDir=%1
echo SourceDir is %SourceDir%
cd /D %SourceDir%
for %%f in (*.avi;*.mkv;*.wmv;*.flv;*.iso;*.rar;*.tbn;*.jpg) do call :sub_MoveFile "%%f"
pause
goto :End



:sub_MoveFile
set dirname="%~n1"
set dirname=%dirname: - CD1=%
set dirname=%dirname: - CD2=%
set dirname=%dirname:-CD1=%
set dirname=%dirname:-CD2=%
set dirname=%dirname:-fanart=%

Echo Moving File %1 to Folder %dirname%
if not exist %dirname% MD %dirname%
copy %1 %dirname%\ > nul
goto :End
:End
(This post was last modified: 2009-05-01 02:43 by AnalogKid.)
find quote
midgetspy Offline
Sick Beard Author
Posts: 866
Joined: Jan 2008
Reputation: 11
Location: Edmonton, Canada
Post: #12
I wrote this to do mine:

Code:
import os
import sys

badWords = ['bluray', 'hdtv', 'hddvd', '1080p', '720p', 'dvd5', 'dvd9', 'x264']

def fixFolder (folder):
        for file in os.listdir(folder):
                if file.endswith('.tbn'):
                        print '    Renaming tbn file', file
                        os.rename(os.path.join(folder, file), os.path.join(folder, 'movie.tbn'))
                if file.endswith('.nfo'):
                        print '    Renaming nfo file', file
                        os.rename(os.path.join(folder, file), os.path.join(folder, 'movie.nfo'))
                if file.endswith('-fanart.jpg'):
                        print '    Renaming fanart file', file
                        os.rename(os.path.join(folder, file), os.path.join(folder, 'fanart.jpg'))
                if file.endswith('-big.png'):
                        print '    Deleting secondary thumb', file
                        os.remove(os.path.join(folder, file))

def sanitizeFileName (filename):
        print 'file is', filename
        goodName = filename[0:filename.rfind('.')]
        goodName = goodName.replace('.', ' ')
        goodName = goodName.replace('  ', '. ')

        for badWord in badWords:
                rPos = goodName.lower().rfind(badWord)
                if rPos != -1:
                        goodName = goodName[0:rPos-1]

        return goodName

def doFolder (whichDir):
        for movie in filter(lambda x: x.endswith('.mkv') or x.endswith('.avi') or x.endswith('.iso'), os.listdir(whichDir)):
                print 'Found file:', movie
                goodName = sanitizeFileName(movie)
                print '  Using sanitized name', goodName

                print '  Creating folder...',
                os.mkdir(os.path.join(whichDir, goodName))
                print ' success.'

                print '  Moving files...'
                for movieFile in filter(lambda x: x.startswith(movie[0:movie.rfind('.')]) and not os.path.isdir(os.path.join(whichDir, x)), os.listdir(whichDir)):
                        print '    Moving', movieFile, '...',
                        os.rename(os.path.join(whichDir, movieFile), os.path.join(whichDir, goodName, movieFile))
                        print ' success.'

                print '  Fixing names...'
                fixFolder(os.path.join(whichDir, goodName))


doFolder(sys.argv[1])

This will NOT work for folders with multipart movies. Take them out before you try, do them manually.
find quote
Nmarconi Offline
Aeon Group
Posts: 77
Joined: Oct 2008
Location: Boston
Post: #13
Below is the link to the .net program I threw together that will convert a folder full of flat movies like this:

All Movies\Movie Title.mkv (or avi, mp4, m4v, iso, mov, img)
All Movies\Movie Title.tbn
All Movies\Movie Title.nfo
All Movies\Movie Title-fanart.jpg

And converts to either of these options:

1)
All Movies\Movie Title\Movie Title.mkv (or whatever the original ext was)
All Movies\Movie Title\Movie Title.tbn
All Movies\Movie Title\Movie Title.nfo
All Movies\Movie Title\Movie Title-fanart.jpg

2)
All Movies\Movie Title\Movie Title.mkv
All Movies\Movie Title\movie.tbn
All Movies\Movie Title\movie.nfo
All Movies\Movie Title\fanart.jpg

THE PROGRAM WILL NOT WORK IF YOU HAVE YOUR MOVIES IN VOB FOLDERS!
THE PROGRAM WILL NOT MOVE TRAILERS!
THE PROGRAM WILL NOT WORK WITH MULTIPLE PART MOVIES!


I HIGHLY RECOMMEND YOU SETUP A TEST FOLDER TO TRY OUT YOUR SPECIFIC SETUP.

http://www.mediafire.com/?indtoihihhy

Hope this helps! Also, seriously - please test it on a small folder to see if your specific setup presents any challenges i did not address. This is intended to be used in very strait forward simple setups.
(This post was last modified: 2009-05-01 22:14 by Nmarconi.)
find quote
ppic Offline
Skilled Python Coder
Posts: 2,711
Joined: Feb 2009
Reputation: 11
Location: France idf
Post: #14
Nmarconi Wrote:Below is the link to the .net program I threw together that will convert a folder full of flat movies like this:

All Movies\Movie Title.mkv (or avi, mp4, m4v, iso, mov, img)
All Movies\Movie Title.tbn
All Movies\Movie Title.nfo
All Movies\Movie Title-fanart.jpg

And converts to either of these options:

1)
All Movies\Movie Title\Movie Title.mkv (or whatever the original ext was)
All Movies\Movie Title\Movie Title.tbn
All Movies\Movie Title\Movie Title.nfo
All Movies\Movie Title\Movie Title-fanart.jpg

2)
All Movies\Movie Title\Movie Title.mkv
All Movies\Movie Title\movie.tbn
All Movies\Movie Title\movie.nfo
All Movies\Movie Title\fanart.jpg

THE PROGRAM WILL NOT WORK IF YOU HAVE YOUR MOVIES IN VOB FOLDERS!
THE PROGRAM WILL NOT MOVE TRAILERS!
THE PROGRAM WILL NOT WORK WITH STACKED FILES!


I HIGHLY RECOMMEND YOU SETUP A TEST FOLDER TO TRY OUT YOUR SPECIFIC SETUP.

http://www.mediafire.com/?indtoihihhy

Hope this helps! Also, seriously - please test it on a small folder to see if your specific setup presents any challenges i did not address. This is intended to be used in very strait forward simple setups.

well...

amazing...
tried with my HD film (around 50 files) worked perfectly!
then with my sd collection (+1500 files) worked perfectly and! better! let me file without existing video file alone in the home directory, just have to delete it to have a clean directory.

thanks!

edit: i haven't mentionned that files are hosted on a NAS, and the operation take less than 5 min
find quote
garyi Offline
Posting Freak
Posts: 1,195
Joined: Oct 2008
Reputation: 0
Post: #15
Hi just to clarify I have a folder with round 70 movies, and of course 70 fan arts 70 nfos etc, these scripts will create folders based on the movie and stick all related files including the movie into it?

How do I use the script (Sorry mac boy here but I do have XP on bootcamp)
find quote
Post Reply