0

So far I have a simple batch script that moves *.mkv files from their source folders to a folder called "Movies". Now I would like FileBot to rename them using the 'find' command, since it (filebot) doesn't seem to support regular expressions. How would I have bash pull a file-name-variable (not sure if this is a thing haha) and use it in find -exec "$FILENAME" kind of pattern?

Here is what I have (pseudo is commented out), I'm sure there's a more efficient way to do this. But hey, I'm a python coder NOT a bash scripter!

mkdir "Movies"
find "Complete/" -iname "*.mkv" -exec mv {} "Movies" \;
#find "Movies/" -iname "*.mkv" -exec filebot -rename "$iname" --db themoviedb"

I need the mv and filebot commands to execute separately as eventually more commands will be called between them.

1
  • How do you want to rename? It it just to lowercase the filename? Dec 30, 2012 at 1:39

1 Answer 1

1

Firstly, for the second line, mv takes wildcards too, so you can simply use

mv Complete/*.mkv Movies

Is it possible that filebot also takes wildcards? i.e. filebot Movies/*.mkv? Otherwise, instead of "$iname", you just want {} again. As you probably know, {} substitutes for the name of the file found, which is the same as *.mkv here. Hence,

find "Movies/" -iname "*.mkv" -execdir filebot -rename {} --db themoviedb \;

N.B. use -execdir instead of -exec for security reasons. From the man page:

There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead.

-execdir command {} +

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files.

4
  • 1
    To clarify, it isn't that mv takes wildcards. The shell expands the patterns before it hands the arguments to mv. gnu.org/software/bash/manual/bashref.html#Shell-Expansions Dec 30, 2012 at 1:34
  • Ah nice catch. Hence, I imagine filebot -rename Movies/*.mkv --db themoviedb should work.
    – Sparhawk
    Dec 30, 2012 at 1:40
  • This is perfect, thank you. I am using 'find' as the *.mkv files are located in subdirectories. Is there an option to use wildcards with subdirectories? The files can be located at any level.. Dec 30, 2012 at 2:43
  • Glad I could help! I don't think you can use wildcards directly for subdirectories, because it's not like they can substitute for "/" for example. I agree with using find in this case then. Good luck with your script!
    – Sparhawk
    Dec 30, 2012 at 3:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .