Rename avi files within nested folders to the top-most folder name and move them there

32 Views Asked by At

I have plenty of movie files saved in folders with roughly the following scheme.

Top-most folder: "The Matrix (1999)", then another folder "matrix movie" and then the actual movie itself: "matrix1999.avi"

I need a small program that can search my main movies folder "Movies" for the above situation and then sort ALL found movie folders as follows:

Top-most folder: "The Matrix (1999)" with the movie inside ""The Matrix (1999).avi" ...the previous middle folder "matrix movie" is now gone.

Incase the last-nested folder contains more that one avi's then its gonna be "The Matrix (1999)-part1.avi", "The Matrix (1999)-part2.avi", etc.

if there are more than one "middle" folders that should be discovered and again the *.avi files moved to the top-most folder, deleting the "middle" ones.

1

There are 1 best solutions below

0
On

I had a similar problem the below one liner solved mine:

find . -printf '%P\0' | pax -0rws ':/:_:g' ./output_folder/

I was also looking for html files that are bigger than a threshold:

find . -name '*.html' -size +1024c -printf '%P\0' | pax -0rws ':/:_:g' ./output_folder/

Hope it helps.