Automator N00b - Movie folder manipulation - Disaster :)

Discussion in 'Mac Programming' started by F-bone, Sep 16, 2015.

  1. F-bone macrumors newbie

    Joined:
    Feb 19, 2014
    #1
    Hi guys,

    I have the following issue which I am trying to resolve and I already managed to wipe my iMac's Home folder while doing various tests :)...

    I have lots of movies directories with the following structure:

    /My Movies/Robocop_1987/movieee/robo.avi
    /My Movies/Back_to_the_Future_1985/moviefolder/back_to.avi
    etc

    In detail: "My Movies" is the top-most directory holding all movie folders, then every movie has its own folder with the complete movie name, then another intermediate folder (i.e. "movieee") and finally a similar name with .avi extension which is the movie file itself.

    What I was trying to do is: Rename the robo.avi file to the name of the topmost folder i.e. Robocop_1987 thus Robocop_1987.avi and move that file to the root of that folder, deleting at the same time the intermediate folder "movieee".

    Final folder structure would be:
    /My Movies/Robocop_1987/Robocop_1987.avi

    Please help me out guys! Can't really afford to mess my computer again or wipe out my movies folder.


    Thank you in advance,
    F
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    I'd be tempted to look at AppleScript or possibly a shell script for this one, rather than Automator.
     
  3. LOLobo macrumors member

    Joined:
    Nov 20, 2014
    #3
    Try out a piece of freeware called FileBot. It may be able to help you.
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    Since I'm in a generous mood, here's a Terminal command to do it.

    Code:
    find "path/to/your/movies/folder" -maxdepth 3 -mindepth 3 -type f | while read theMovieFile; do echo theMovieFile: "$theMovieFile"; theMovieFolder=$(dirname "$theMovieFile"); theDestFolder=$(dirname "$theMovieFolder"); echo "theMovieFolder: $theMovieFolder"; echo "theDestFolder: $theDestFolder" ; mv "$theMovieFile" "$theDestFolder" ;  rm -rf "$theMovieFolder"; echo --- ;  done
    ...just insert the correct path to your movies folder. I strongly suggest that you make a test Movies folder and make sure you're happy with how it works before using it on the real thing.

    Of course, you can run this as part of an Automator workflow if you really need to. Nothing wrong with running it from the Terminal though.

    Hope that helps
     
  5. F-bone thread starter macrumors newbie

    Joined:
    Feb 19, 2014
    #5
    guys just got here after a crazy day at work to find some serious answers waiting! thank you very much will try all of them starting with superscape's terminal command. I will test it first, as you recommended, and let you know. And yes it definitely helps, psychologically the least until tested, totally when it works.

    I hope it works even if inside the movie folder exist single files or folders without the intermediate directory.
     
  6. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #6
    Not as it stands, but it should be fairly easy for you to tweak. I suggest you read up on the find command (which is what my script uses).

    At the moment it looks for any file, exactly three folders down from the starting folder. You can change that with the -maxdepth and -mindepth parameters as required. As I said before, use with care and test on a dummy folder!
     
  7. F-bone thread starter macrumors newbie

    Joined:
    Feb 19, 2014
    #7
    wil do.. at work now, will test over the weekend. thanks again for the effort and interest.
     
  8. F-bone, Sep 21, 2015
    Last edited: Sep 21, 2015

    F-bone thread starter macrumors newbie

    Joined:
    Feb 19, 2014
    #8

    just to let you know the command worked like a charm! super-fast and did what it is supposed to do. much appreciated! envy your skillz and all :) --

    EDIT: after some more testing I think it does not rename the randomname.avi file to topfoldername.avi.. after testing to around 10 movies and got the correct results, I recreated an intermediate folder and renamed the avi again to something random leaving the top folder with the full movie name.. i did this to some of the movies and left others with topfoldername/topfoldername.avi structure.... I then ran the command and although it found the changed-by-me-test-folder, it moved the avi in the topfolder root but did not rename it?

    EDIT2: I think I got correct results the first time because the avi file inside the intermediate folder was already named as "topfoldername".avi

    EDIT3: this and another thread made me start - although a bit old for that - learning some Python2, hopefully I will write my own code to do this renaming/moving soon... will let you know :)
     

Share This Page