Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

F-bone

macrumors newbie
Original poster
Feb 19, 2014
15
0
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
 
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
 
  • Like
Reactions: F-bone
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.
 
I hope it works even if inside the movie folder exist single files or folders without the intermediate directory.

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!
 
  • Like
Reactions: F-bone
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!

wil do.. at work now, will test over the weekend. thanks again for the effort and interest.
 
wil do.. at work now, will test over the weekend. thanks again for the effort and interest.


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 :)
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.