Move all subfiles into parent folder

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Move all subfiles into parent folder Fri Feb 03, 2023 3:01 am • by MasterRee
Hi everyone.

I have a large number of music directories with a mixture of subfolders, audio files and non-audio files. I'm trying to move all of the subfile contents of specific subdirectories named "FLAC" into the parent of each FLAC directory respectively. I want to move all subfile contents of FLAC, including the contents of any subfolders, but I do not want to move the subfolders themselves.

My structure is like so:
Code: Select all
/ExternalDrive/_To Sort/OC Remix/AlbumName/FLAC/song.flac


The monitored folder is "OC Remix".

Sometimes the structure goes down another level like so:
Code: Select all
/OC Remix/AlbumName/FLAC/CD 01/song.flac

There is no consistency for the "CD 01" level, or whether there is a "CD 01" level subfolder, so I'm trying to account for that variable.

The goal is to move "song.flac" and any other files of any kind in that directory (like artwork.png, tracklist.txt, or Artwork directory) into the "AlbumName" directory, leaving "FLAC" (and if it exists "CD 01") where they are, but completely empty.


Below is a screenshot of my current rule that does find the correct matches, but does not move the files. I embedded a simple shell script to move the file up a single folder level, but instead the files move up as many as four directory levels. They always move to "_To Sort", which is one level above the monitored folder and (again) up to four levels above the matched file that I'm intending to target. The link also shows a screenshot of a sample album from this folder structure.

https://imgur.com/a/m96DWxk

If this were working properly, there is a second rule that will run the rules on folder contents, so my expectation is that for directories with a "CD 01", Hazel will move the files up one level into the FLAC folder on the first run, then cycle through again and move them into the "AlbumName" folder, at which point the files will no longer match the rule and will not be moved up again.

Can anyone more savvy in Hazel or shell scripting point out my mistake as I know this should be very simple. If there is an easier way to do this, I'm all for it. Right now I'm driving myself bald working on this. :?



EDIT: So I realized after a bit more testing and reflection that the script is being run relative the monitored folder and not relative to the matched file. The shell command to move up a single level is moving everything up a single level from the monitored folder and not from the matched file. Why is this happening and what would be the proper syntax to move up one level relative to the matched file?

I also realized that I forgot to enclose $1 in quotes and add an exit status in the script, so I updated the script as seen below for good measure, but the issue persists:

mv -v "$1" ..

exit 0
MasterRee
 
Posts: 19
Joined: Mon Jan 01, 2018 8:21 pm

Re: Move all subfiles into parent folder Fri Feb 03, 2023 10:29 am • by Mr_Noodle
$1 is the full path so it should be relative to the specific file. That said, why not use the Move action. One of the destinations you can select is the parent folder.

As for the behavior, I suggest going through the troubleshooting guide here: https://www.noodlesoft.com/kb/hazel-tro ... ing-guide/

Report back with the results.
Mr_Noodle
Site Admin
 
Posts: 11174
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move all subfiles into parent folder Fri Feb 03, 2023 6:09 pm • by MasterRee
Thanks @Mr_Noodle. I'll follow those suggestions and post the results when I get a chance to run through the guide. As for using the Move action, that was where I started before resorting to the Shell script. I thought I was misunderstanding the action options and it was intended to move to a parent folder. Is this the action you were meaning to "Move" to folder: "enclosing folder"? Here is the rule I tried first, but like the shell script, once Hazel matched and ran the rule the files never moved. The log showed the rule matching and running, but there was no change. If that isn't what you meant, could you clarify what the rule would be to move items to their parent folder?

https://imgur.com/zyh4VB7

Thanks!
MasterRee
 
Posts: 19
Joined: Mon Jan 01, 2018 8:21 pm

Re: Move all subfiles into parent folder Fri Feb 03, 2023 8:13 pm • by MasterRee
Well, I have no idea why, but the Hazel rule I posted above using the native Move command is now working as I expected it to originally. Since I last tested the rule, I did update owner permissions recursively on the drive as well as revoke and grant full disk access to Hazel once again (just to rule out any possible issues there).

So, thanks for the help! Problem is solved and it is very satisfying to see those thousands of files organizing as intended.
MasterRee
 
Posts: 19
Joined: Mon Jan 01, 2018 8:21 pm


Return to Support