Batch program to move files to separate folders

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
AnalogKid Offline
Fan
Posts: 644
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: 867
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,663
Joined: Feb 2009
Reputation: 10
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,196
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
ppic Offline
Skilled Python Coder
Posts: 2,663
Joined: Feb 2009
Reputation: 10
Location: France idf
Post: #16
yes it move all related file in folders.
all you have to do is launch the program, select the path and clic start !
find quote
garyi Offline
Posting Freak
Posts: 1,196
Joined: Oct 2008
Reputation: 0
Post: #17
Thanks Nmarconi I have no idea how many hours your little programme has just saved me, it worked flawlessly.
find quote
Nmarconi Offline
Aeon Group
Posts: 77
Joined: Oct 2008
Location: Boston
Post: #18
garyi Wrote:Thanks Nmarconi I have no idea how many hours your little programme has just saved me, it worked flawlessly.

Glad to help out!

garyi Wrote: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)

I'm not sure this will work on a mac running xp via bootcamp as the files need to be in a windows directory. I would seriously test it on a folder with only a few movies first if you are going to attempt it. I don't know anything about macs.
(This post was last modified: 2009-05-01 21:55 by Nmarconi.)
find quote
garyi Offline
Posting Freak
Posts: 1,196
Joined: Oct 2008
Reputation: 0
Post: #19
Well as I say it worked flawlessly. Importantly I booted into XP proper.

Not meaning to step on more knowledgeable toes, but basically XP under bootcamp, is XP proper straight and proper. My files are on a nas which XP picks up in a proper windows styleee.
find quote
Nmarconi Offline
Aeon Group
Posts: 77
Joined: Oct 2008
Location: Boston
Post: #20
garyi Wrote:Well as I say it worked flawlessly. Importantly I booted into XP proper.

Not meaning to step on more knowledgeable toes, but basically XP under bootcamp, is XP proper straight and proper. My files are on a nas which XP picks up in a proper windows styleee.

Ahh - i was worried the files were stored locally on your mac and i didnt know if that would screw it up. Glad it worked!
find quote