Thread Rating:
  • 0 Vote(s) - 0 Average
Batch program to move files to separate folders
#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!
Reply
#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.
Reply
#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.
Reply
#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
Reply
#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.
Reply
#6
I'm sure fekker made one ages ago that I used at the time to transfer over to folders.
Reply
#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.
Reply
#8
Thanks Nmarconi! I'll definitely use it. 2,000+ collection. Sad
Reply
#9
http://forum.xbmc.org/showpost.php?p=256...stcount=68
Reply
#10
david81 Wrote:http://forum.xbmc.org/showpost.php?p=256...stcount=68

Blimey, how'd you manage to find that?
Reply
#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 Confusedub_MoveFile "%%f"
pause
goto :End



Confusedub_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
Reply
#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.
Reply
#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.
Reply
#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
Reply
#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)
Reply



Batch program to move files to separate folders00