File-to-folder script.

Posted by Jon | HTPC,Tips, Tricks & Guides | Thursday 19 February 2009 11:07 am

Foreword

f2fguiexample_0 I have since taken up learning Visual Basic and have converted the file2folder script to a feature-filled application called file2folder GUI (original, eh?).  You can read more about it at the Google Code site.  Download is available in the downloads section, or at Google Code.

Otherwise, the script is still available…read on if that’s what you’re interested in…




I keep seeing this crop up more and more as the popularity of Media Browser increases.  It has to do with those that have large movie collections, but do not have their individual movie files (in AVI, MKV, MP4, DIVX, WMV, etc.) in a folder of the same name – which Media Browser requires.

I faced this same issue also when I was wanting to get away from MyMovies.  I had all of my movies thrown into a couple of categorized directories, but that was it.  I couldn’t imagine manually creating 1500 folders for my movies, so I called upon my batch scripting abilities (I’m a systems administrator by trade) and came up with this little snippet of code that I still use to this day (I have a default folder that I convert all of my new DVD/BluRay discs to and then I run this once the output file is completed).

@echo off
for %%a in (*.*) do (
 	md "%%~na" 2>nul
 	move "%%a" "%%~na"
)
Just copy this into a text file and rename it to a .bat extension.  You will place the .bat file into the directory containing your movie files and then double-click it.  It will automatically create a new folder of the same name of each of your movie files and then move that file into it.  Voila!  If you have any subtitles that are named the same as your video files, they will get moved into the same folder as well (any file of the same name will, actually).  So if you have a movie called The Transporter.avi, a The Transporter.srt subtitle file, and a The Transporter.jpg image file inside your Movies directory, when you run the script all three files will be moved to Movies\The Transporter directory.





If you have multiple directories, you will need to do the same for each of them as this is not recursive code.  I’d rather it not be so that you have some level of control over it.  I also would not run this in any TV series folders as it will throw your individual episodes into their own folders.  Also, if you have any of your files marked as hidden or read-only, they will not get moved.

Warning!

Depending on where you have your movies stored and/or what is in your movies directory, this could be a very dangerous script.  Keep in mind that this script will move EVERYTHING within the directory it is run in except for hidden and read-only files.

Due to the number of issues, do not not run this against network locations unless the drive is mapped to a local drive letter.

End Warning!


Anyway, hope this helps some of you out!

Update:

I have not been able to reproduce this on at least a half-dozen systems using four different OSes (2008 Server x64, 2003 x86/x64, Vista Ultimate x86/x64 and XP x86, but I thought I should put it out since at least one person has commented on it.  Apparently this script created odd-named folders and did not move any files.  As I said, I have not ever had any issue with this script and it has moved over 2000 movies for me.  Anyway, if you plan to use this, please test it out with some dummy files first (you can use any kind of files, just make sure you do it within a safe folder).

Update 2:

It appears there may be an issue with copying the code off this post and inserting it into your own .bat file.  So, in order to reduce (or resolve) the issues with it, I’m including the exact .bat file that I use.  So far, there have been no reported issues with it.  You can get it here (RAR format).

  • Share/Bookmark

42 Comments »

  1. Comment by Bobo — February 21, 2009 @ 5:59 pm
    Browser: Firefox 3.0.6 OS: Windows Vista

    This didn’t work for me.. Running Vista Home Premium. Would’ve been nice, but it ended up creating me more hassle.. It split all the names up, and created tons of extra folders, e.g. Benjamin Button became óbenjamin and óbutton along with tons of other movies. I still don’t know if any of the folders i deleted had any film in them, it created over 200 folders, and i was DAMNED if i was gonna search every one of them individually, i decided to just cut my losses and deleted the lot. The ones i did check had nothing in them, so no files were moved AFAIK. It just created a whole heap of uselessly named folders..

    To end, Once Upon A Time In America, created about 12 extra folders, where the words ‘a’ & ‘in’ already appeared in other file names.. So Home Premium Vista? Stay away..

    [Reply]

    Jon Reply:

    Not sure why it didn’t work for you, I just copied the code into a batch file and ran it against a bunch of files here at work and it worked perfectly (I even created a “Once Upon A Time In America.avi” dummy file and it worked like it always does). So far, it has worked for me on XP 32-bit, Vista Ultimate 32 and 64-bit, 2008 Server 64-bit and 2003 Server 32 and 64-bit. It also works over the network and locally for me (my network location is actually a linux-based server using ReiserFS) I have not made any changes that would directly affect the functionality of this script. Considering the special characters that are being created in your folders, I would have to say something else is wrong.

    [Reply]

  2. Comment by MHealy — February 27, 2009 @ 10:09 pm
    Browser: Internet Explorer 8.0 OS: Windows 7 x64 Edition

    I had the same issue on Windows 7 Beta (build 7000) I just created a bat named movie_folders.bat using the text from above and got odd named folders with no files in them. I took a screenshot for review here: http://sites.google.com/site/hack7mc/images/share/movie_folders.png

    [Reply]

    Jon Reply:

    You guys have me stumped, I just can’t recreate this and I have no idea what could cause that. Do you have UAC enabled (not that I think that would cause it either, but I don’t even know where to start)? Here is a link to the file2folder.bat that I have used on no less than a half-dozen systems without issue. If either of you want to give it a try and let me know if the same thing happens, I’d appreciate it. Download. Make sure to set the bat file to hidden if it doesn’t carry over.

    [Reply]

  3. Comment by MHealy — February 28, 2009 @ 4:48 pm
    Browser: Internet Explorer 8.0 OS: Windows 7 x64 Edition

    The downloaded file seems to work just fine when I tried it this time. I have no idea what the problem could have been though. Copy and pasting the text above didn’t work but typing it out myself in notepad did. Odd.

    [Reply]

  4. Comment by MHealy — February 28, 2009 @ 4:59 pm
    Browser: Internet Explorer 8.0 OS: Windows 7 x64 Edition

    One other thing, do you mind if I post your .bat file with some instructions and links back to this post on my site? I’ll rehost the .bat file so it doesn’t use any excess bandwidth of yours as well.

    [Reply]

    Jon Reply:

    That is odd. I wonder if there is some weird formatting caused by copying the code off of the site (hidden breaks or something)? That would make sense, but I actually did just that and it still worked for me. I’ll try to edit it so that it displays with absolutely no formatting and just go ahead and link the batch file in my post, using the code as an example of its content.

    Post the .bat at will. It’s just common DOS :)

    [Reply]

  5. Comment by Jason — March 14, 2009 @ 12:08 am
    Browser: Internet Explorer 7.0 OS: Windows Vista

    Perfect!!
    Searched in google for an app to move files for MyMovies and found this – the power of batch files is so overlooked!
    Been in IT for 20+years and used to use DOS bat’s all the time, didn’t even occur to me – how lazy is Windows making us ???

    [Reply]

  6. Comment by Colin pastuch — June 3, 2009 @ 5:09 pm
    Browser: Firefox 3.0.5 OS: Windows XP

    I had the same problem as others. When I created the batch script based on your text above it would create the folders but not move the files into them. When I run the bat that you rar'ed and attached to your site it works perfectly.

    Thank you so much for this. I can finally try out Mediabrowser. Whats the best meta tool and could you post a guide to using your favorite?

    [Reply]

    thehtpc Reply:

    The best is relative. I actually use a combination of Salami’s Movie Organizer and Meta Browser for movies and still use MediaScout for TV.

    I use SMO still because it provides more accurate data using IMDB than tMDB and allows me to pick the poster I want from IMPAwards. After saving there, I open it up in Meta Browser to fill in the blanks (parental rating and whatnot), grab backdrops and actor images. MediaScout has always been my preferred TV fetcher, but I’m starting to let Meta Browser take care of that duty also since MS is no longer developed or supported.

    My best advice is to try them all and find one you like best. I have several posts announcing new tools that have been released over the past couple of months and I believe I have them all linked on the plugin index.

    [Reply]

  7. Comment by Ben — August 9, 2009 @ 1:03 am
    Browser: Firefox 3.0.13 OS: Windows XP

    Found this post by googling.
    This script is EXACTLY what I’ve been looking for!
    I have to sort a collection of about 12,000 files and I almost gave up on sorting it!
    You’re a genius!

    [Reply]

  8. Comment by Bob — August 20, 2009 @ 3:20 am
    Browser: Firefox 3.0.10 OS: Windows XP

    Just tried this & it worked perfect for me – Saved me LOADS of time creating a movie database – Thank you!

    [Reply]

  9. Comment by Thomas Lewis — September 10, 2009 @ 7:26 am
    Browser: Internet Explorer 7.0 OS: Windows XP

    Anybody know the script to do this in linux? All my stuff is on my linux server and the DOS command wont run even if i do it via the network drive on my XP machine or 7mc THANKS

    [Reply]

  10. Comment by bbg454 — October 8, 2009 @ 2:45 pm
    Browser: Firefox 3.0.14 OS: Ubuntu 9.04

    Bash script for the linux kiddies

    *use at your own risk*

    /bin/bash

    DIR=`pwd`

    find $DIR -maxdepth 1 -type f | while read FILE
    do
    FOLDER=`echo $FILE | sed ‘s/\(.*\)…./\1/’`
    echo ‘this is my file’
    echo $FILE
    echo ‘this is my folder’
    echo $FOLDER
    echo ‘==============’
    mkdir “$FOLDER”
    mv “$FILE” “$FOLDER”
    done

    [Reply]

  11. Comment by Anoop — November 4, 2009 @ 1:11 am
    Browser: Firefox 3.5.3 OS: Windows XP

    its a wonder! I was really worried about how i am gonna find the time to create folders for all my folderless files and out of the blue you came up with a nice and convenient way of doing it.

    [Reply]

  12. Pingback by Storing metadata locally « meta<browser/> — November 4, 2009 @ 10:08 am WordPress 2.8.5

    [...] For those who have all their movie files in one folder, Jon from theHTPC.net has written a File-to-Folder script which will create a new folder with the same name as your movie files and then move the file into [...]

  13. Comment by Peter — December 5, 2009 @ 10:43 pm
    Browser: Firefox 3.5.5 OS: Windows XP

    Please help me.
    I have all my music and video files on the network (NAS drive)
    I like to do identical process as this batch is doing, but on the network.

    I used this batch on my PC, work excellent, but when I try to use this batch on my NAS drive it went south.

    I copied batch to NAS to same directory as my moovies. After execution of batch, nothink happend, but later I found it actually mooved my system files from Windows folder.
    PLEASE DO NOT TRY IT AS I DID. It will destroy your OS.

    [Reply]

    Jon Reply:

    Very odd. I have used it locally and over the network without issue.

    [Reply]

  14. Comment by lance — December 7, 2009 @ 4:37 pm
    Browser: Internet Explorer 8.0 OS: Windows 7 x64 Edition

    Windows 64 bit, ulimate – a success story after trials and tribulations.

    I tried this initially. Didn’t work – just created a bunch of empty folders.

    Poked around for another similar utility. No luck. Wasted an hour doing it.

    Came back and actually looked at the error messages as it ran – “Access Denied”.

    Turned off UAC (required a reboot). Ran the script. Worked perfectly.

    Turned back on UAC. 10 minutes and I’m very, very happy!

    Now I’m going to go run XBMC’s Media Companion and finish something that would have taken me weeks to do on my own.

    THANK YOU FOR THIS SCRIPT!!!!!!!!

    [Reply]

  15. Comment by scoutfu — December 19, 2009 @ 6:00 pm
    Browser: Firefox 3.6b3 OS: Windows 7

    Hi, nice script :)

    I was just wondering if you had a script to undo what the script did?

    Cheers

    [Reply]

    Jon Reply:

    Unfortunately, no. It’s possible if you output all changes to a text file so that it can be reversed, but I’ve never need to go that far with it.

    [Reply]

  16. Comment by PChammer — January 1, 2010 @ 9:42 pm
    Browser: Firefox 3.6b5 OS: Windows 7

    Hi, I found this due to having so many downloads, not movies, but files. I am a freeware junkie and let me say, this little script is exactly what I’ve been looking for. I create icons for software, like Malwarebytes anti malware icon and others, plus do other graphics work and this will come in handy for all my files there as well. It’s too bad you couldn’t create the undo, add some features, create a small app out of this, hell, I’ll even make the icons and everything if you want. This has to be the handiest script I’ve run across in a long time. Thank you for this!

    [Reply]

  17. Comment by DK — January 3, 2010 @ 11:37 pm
    Browser: Internet Explorer 8.0 OS: Windows Vista

    Firstly thanks for the script, however I’m unable to run it successfully on my windows home server. Giving me Access Denied error message. Any suggestions?

    [Reply]

    Jon Reply:

    Make sure you are running it locally and not over the network. Make certain you have permissions to move files on the location you are running the script. Finally, make sure that the files you are attempting to move are not in use. Other than that, there is no reason for it not to work. There’s nothing complicated going on with it at all.

    [Reply]

  18. Pingback by Mehr Flair im MediaBrowser mit StarkCovers «Hyperraum-Umgehungsstrasse — January 14, 2010 @ 9:01 am WordPress 2.8.6

    [...] ihr somit auch noch keine "folder.jpg" pro Film haben, lege ich euch folgenden Guide ans Herz und dieses kleine Script, welches jeder einzelnen Datei in einem Verzeichnis einen eigenen Ordner mit dem Dateinamen [...]

  19. Pingback by Film Info! Organizer, MetaDaten für Filme in Deutsch «Hyperraum-Umgehungsstrasse — January 29, 2010 @ 6:56 am WordPress 2.9.1

    [...] dem Filmnamen erstellt und der besagte Film in diesen Ordner verschoben. Hierzu gibt es auch ein kleines Script (File-to-Folder), welches die Aufgabe gut erledigen [...]

  20. Comment by Matt — February 28, 2010 @ 6:54 pm
    Browser: Google Chrome 4.0.249.89 OS: Windows XP

    I too had the issue where it moved everything in c:\windows rather than the directory it was in. It might have something to do with the quote marks you use. My issue was on WHS (Windows Server 2003).

    Time to rebuild :(

    [Reply]

    Jon Reply:

    There’s only an issue if you run it against a network share that is not locally mapped to a drive letter. The quotes are necessary if you have space in any of your movie names or paths.

    [Reply]

  21. Comment by MattWA — March 4, 2010 @ 5:52 am
    Browser: Firefox 3.0.15 OS: Fedora 10

    I wasn’t able to get the above Linux script to work so figured another way to do it.

    this is for Linux, not windows. This will work provided there is only one file associated with the movie. If you have other stuff like folder.jpg or something it probably won’t be suitable.

    Thanks,

    #!/bin/bash
    find . -name '*.*' | \
    while read filename
    do
          mkdir "${filename%.*}"
          directory=${filename%.*}
          mv "$filename" "$directory"/"$filename"
    done

    [Reply]

  22. Comment by MattWA — March 4, 2010 @ 5:59 am
    Browser: Firefox 3.0.15 OS: Fedora 10

    It seems when posting on here the tabbed spaces are removed which cause the above linux scripts to not work, as previously mentioned by others.. guess I didn’t see that.

    The lines starting with mkdir, directory, and mv, are tabbed spaced.

    [Reply]

    Jon Reply:

    I fixed it for you. WordPress does this by design…it’s not so much a bug (but an inconvenience either way). You can copy in tabbed spaces so long as you enclose you enclose it within <pre></pre>.

    I also used the code tag since not using can introduce some oddities when copying text directly from WordPress…especially script code.

    [Reply]

  23. Comment by kay_emi — March 5, 2010 @ 4:15 am
    Browser: Firefox 3.6 OS: Windows 7

    Update 2:

    It appears there may be an issue with copying the code off this post and inserting it into your own .bat file. So, in order to reduce (or resolve) the issues with it, I’m including the exact .bat file that I use. So far, there have been no reported issues with it. You can get it here (RAR format).

    Hi Guys this file no longer exists. Can anyone help.

    [Reply]

    Jon Reply:

    Yep, it’s in the download section.

    [Reply]

  24. Comment by Richard — March 11, 2010 @ 10:58 am
    Browser: Firefox 3.5.8 OS: Windows XP

    I used this and it worked perfectly, thanks!

    But – how would I reverse this action?

    Is their a script that can undo this, and take the files back out of folders??

    I ask, because I may one day not want Thumbnails, and want my movies in list format as they were before I ran this script.

    Thanks

    [Reply]

    Jon Reply:

    I don’t have anything to undo it. You could do a simple search by extensions (ex.: *.avi, *.mkv) and then cut and paste all the found files to a different directory quite easily though.

    [Reply]

  25. Comment by nick — March 22, 2010 @ 1:19 am
    Browser: Firefox 3.5.8 OS: Windows XP

    this file doesn’t work for me at all. I was so disappointed, I have soo many movie files I need to organize and was hoping this would’ve helped. Tried it on my local hdd’s and also on my external hdd’s… absolutely didn’t work. Oh wells. guess I have to find another way. thanks anyways jon

    [Reply]

    Jon Reply:

    Did you download it or copy it from the page?

    [Reply]

  26. Comment by matt — May 23, 2010 @ 12:01 am
    Browser: Firefox 3.6.3 OS: Windows Server 2003

    Just a note that

    Movie.avi
    and
    Movie.avi.properties

    will not be sorted into the same directory. Note sure how many others have files setup like this, but I just wanted to note it. Otherwise, works great! Thanks.

    [Reply]

    Jon Reply:

    Associated files are on the board as I learn. Hopefully. It won’t be a long wait.

    [Reply]

  27. Pingback by File2Folder Gui «Hyperraum-Umgehungsstrasse — July 6, 2010 @ 5:30 am WordPress 3.0

    [...] für Film, MP3 für MP3 in einzelne Ordner verschoben haben. Es gab schon vor Ewigkeiten kleine Scripte die dies automatisiert und für jede Datei einen Ordner erstellt haben mit dem Dateinamen ohne die [...]

  28. Comment by TCBW — July 15, 2010 @ 10:25 am
    Browser: Internet Explorer 8.0 OS: Windows 7 x64 Edition

    I suspect the reason that some people have it work and others don’t is due to the fact some editors mess with the ” when it sees pairs of them. If they are converted to open ” followed by a close ” then the command process (thing that runs bat files) will see files with spaces in them as multiple parameters instead of one.

    Pasting the script into notepad and checking that the ” is a normal one as per the standard shift ‘ should make this issue go away.

    [Reply]

  29. Comment by Alden — July 20, 2010 @ 11:07 am
    Browser: Google Chrome 5.0.375.99 OS: Windows 7

    most excellent! thanks a lot man. saved me soooo much time and aggravation. :D

    [Reply]

RSS feed for comments on this post. TrackBack URI

Leave a comment