Automator: Move files into new subfolder based on file’s name

applescriptautomatorbashfile-transferfinder

Disclaimer, this may not be something Automator can do.

I have a large directory of movie files. In order to use a piece of software, each movie needs to be in it's own folder. I'd like to create some sort of automation to do the following:

  • Create folders named after each filename ex: Cool Movie.m4v => ? Cool Movie ƒ
  • Move movie file to corresponding folder

I'm hoping that between Automator, Bash, or AppleScript, there's a way to do this.

Clarification:

If I have a folder that looks like this:

  1. Movies ƒ
    • Movie A.m4v
    • Movie B.m4v
    • Movie C.m4v

I'd like it to look like this after:

  1. Movies ƒ
    • Movie A ƒ
      • Movie A.m4v
    • Movie B ƒ
      • Movie B.m4v
    • Movie B ƒ
      • Movie B.m4v

Best Answer

In Terminal, change directory to the folder containing the files, e.g.:

cd /path/to/files

Then use the following compound command to do what you've asked:

for f in *.*; do [ -f "$f" ] || continue; mkdir "${f%.*}" && mv "$f" "${f%.*}"; done

If you want to limit it to just .m4v files, then change for f in *.*; to:
for f in *.m4v;

Note that this doesn't make a folder with the ƒ character you've shown, but if it's part of the wanted folder name, then change both occurrences of "${f%.*}" to: "${f%.*} ƒ"