1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-21 23:42:23 +00:00
7 How to Create a Folder for Each Movie
Carra Bussa edited this page 2018-09-26 17:28:50 -05:00

OK, so QUICK AND DIRTY for right now, I'm in a hurry and not prepared to actually write this.=, but it popped up so here we go.

Linux: You've got a bunch of movies in a single directory and you want to place them in separate subs for Radarr.

Great, but lets work with a play directory first, unless you like accidentally destroying your media files with a typo

This is NOT exactly what you want, it's got ugly output but will literally create what you asked for: create a directory for each file.

Change to a test directory. (mkdir test; cd test.) Create some dummy files to play with. (touch {a,b,c,d,e}.mkv {f,g,h}.m4p a.txt c.srt h.iso pizza.is.good.wav) They're all 0 byte files so they won't REALLY play, but you knew that, right? They're still good enough for testing though. ls -l to make sure you know what you've got (should be 12 files above. Add more if you want.)

Here goes what you asked for: create a directory for each and every file in this directory, and then later we move the corresponding files in.

Let's do a test run: for a in d.* ; do b=`basename "$a"`; echo mkdir -v " ${b%.*}" ; done

The code above should be: b = tic basename "$a" tic ; ... it's not showing up Tic" is the lower-case tilde, just to the left of the 1 key on a US keyboard. I think the syntax ${x=y} works as well, but I'm old school.

This should give the output: mkdir -v d It should NOT actually create the directory yet. If you don't get that as output, check your syntax until you do. There are quotes and tics and stars and punctuation and spacing and all KINDS of strange and wondrous stuff you've got to get exactly right.

Now let's test the m4p files: for a in *.m4p ; ... Right? Just change the pattern. You should see 3 mkdir commands for f, g, and h.

Great. Let's test it with everything for a in * ; ...

Now you'll see 12 mkdir commands, one for each of the files with the extension removed.

Now there's a minor problem here: "mkdir a" for a.mkv and "mkdir a" for a.txt will EACH create directory a, but the 2nd one will fail since the first succeeded. That's what the IF statement is for above: if target directory does (not) exist, do this instead. Adding the if statement "is left as an easy exercise for the reader", although I'll get around to it here someday.

So: at this point you can be paranoid and copy the output in the clipboard and paste it straight back on the command line, or edit in a file and run it,. Or you can even: "if .... > output" to generate the same thing again, and run it by sourcing (. output) or run it directory by chmod +x output; ./output. Or lots of redirected shell things.

The actual thing to do is check the output above, make sure it's correct, and then run it for real by removing the echo for a in * ; do b=`basename "$a"'`; echo mkdir -v " ${b%.*}" ; done (Remember: b=tic basename "$a" tic; ...)

You'll get a few errors from creating duplicate directories, but it'll all still work just fine. If you're still paranoid change the pattern to suit: My* or The* or XXX. (WAIT, how did THAT one get in here? ;-) )

Now go make a file of: a.blah.more.stuff.mkv and run it against that -- you'll get a directory of: a.blah.more.stuff. It only rips off the LAST extension if you will, and creates whatever's left over.

windows: Play with: for %a in (*.txt) do echo mkdir "%~na" It's the same but different.

To move 'em in their corresponding subs:

for a in / ; do b=`basename "$a"` ; mv -v "$b" "$b" ; done (Tics here too)

Winders: for /d %a in () do move "%a" "%a"

Excuse me, my Pizza is calling and isn't getting any warmer.