Goal: Append (rename) and move only those files whose path contains a specific directory name, at any level.
Extracting files from trees based on directory names. From years of periodic mobile backup, trying to extract (move) those files that are inside of directories where any of the parent directories match a name on a custom "media directory list". Append the full path as a prefix for each file and place appeneded files into a single OUTPUT dir. (Using file extension as a selector would not work for my purposes, must be one of the parent dir name.) For example,
Input dirs (each with many subdirs):
20011231-bkp-1 20021231-bkp-2 20031231-bkp-3
Output (appended files in a single "OUTPUT" dir):
20011231-bkp-1__dir-a__dir-b__dir-c__WhatsApp Images__imag-1.jpg 20021231-bkp-2__dir-a__dir-b__dir-c__WhatsApp Images__Sent__imag-1.jpg 20031231-bkp-3__dir-a__Camera__imag-1.mp4 20031231-bkp-3__dir-a__Camera__dir-x__imag-1.mp4
media dir list (these dirs can be anywhere in the path, note spaces). Rename and move only but all files within these, exact match, recursively:
WhatsApp Images WhatsApp Audio Recorders Camera
This works for appending and moving, but have trouble restricting only to those files that are inside the "media dir list":
find 1 -type f| perl -ne 'chop;$from=$_;$to=$_;$to=~s/\//__/g;system("echo mv $from $to")'