I'm trying to find a script that would basically look recusively at a directory, and if the script finds file that are .flac files, it will create a subfolder called FLAC in that same folder, and move the .flac files only into that directory. It may find 30 flac files in the same directory, so I don't want it to meltdown once it realizes the folder already exists, etc...
Example folder/file layout:
Base path is
/files/musicSubdirectories currently look like
/files/music/artist /files/music/artist/album1 /files/music/artist/album2Files appear as
/files/music/artist/album1/01-song 1.mp3 /files/music/artist/album1/01-song 1.flac /files/music/artist/album1/02-another song.mp3 /files/music/artist/album1/02-another song.flac /files/music/artist/album2/01-yet another.mp3 /files/music/artist/album2/01-yet another.flacSo essentially I want it to become:
/files/music/artist/album1/01-song1.mp3 /files/music/artist/album1/02-another song.mp3 /files/music/artist/album1/flac/01-song 1.flac /files/music/artist/album1/flac/02-another song.flac /files/music/artist/album2/01-yet another.mp3 /files/music/artist/album2/flac/01-yet another.flac
The whole idea, is that after scanning in a ton of my CDs, I have a lot of folders with mixed versions...so media players end up playing the song song twice (first the mp3 version, then the flac version)...
Is it possible to script something that would leave the directory as-is, if no mp3 files exist? (only flac?) Thus, if a folder had solely .flac files, it wouldn't create a subfolder...leave it as-is. The only hiccup I would see would be that it would have to look for mp3 files, as there might be other files in the folders (jpg cover files, etc..)
files):find . -type d -exec sh -c 'ls "$0"/*.mp3 >/dev/null 2>&1 && ls "$0"/*.flac >/dev/null 2>&1 && mkdir "${0}/FLAC" && mv "${0}"/*.flac "${0}/FLAC"' {} \;- it's not very efficient but it should work with all kinds of file names / dir names. Addechobeforemkdirand beforemvto see what it does without actually running those commands.shopt -s nocaseglobif you're usingbashorunsetopt CASE_GLOBif you're usingzsh.