Page 1 of 1

Use of RAR archive correctly in subfolders with Hazel

PostPosted: Sun Apr 30, 2017 3:46 pm
by rleaver152
Issue: I am monitoring a nested set of folders in Hazel for any files which do not start with "sec_" . I then securely RAR any matching files with an embedded script which results in files prefixed sec_ and ending .rar The original file is removed on successful RAR completion by the RAR switches chosen.

So far so good. However, the .rar file is *always* created at the top of the monitored folder set, *not* in the subfolder containing the original target file. I can find no combination of rule/ordering which achieves what I want.

Yes I have read the sticky file in the FAQ about subfolders. The problem may stem from RAR thinking that the source directory is the top folder where the script is invoked, not the subfolder descended to.

Please can you assist - screenshots attached.

thanks
Image
Image
Image
Image
Image

Re: Use of RAR archive correctly in subfolders with Hazel

PostPosted: Mon May 01, 2017 10:21 am
by Mr_Noodle
It's always a bad idea to assume the current directory in shell scripts. Either cd to the correct directory or use full paths for any file arguments.

Re: Use of RAR archive correctly in subfolders with Hazel

PostPosted: Mon May 01, 2017 11:51 am
by rleaver152
Mr_Noodle wrote:It's always a bad idea to assume the current directory in shell scripts. Either cd to the correct directory or use full paths for any file arguments.


Thanks but is there anything helpful you can suggest, that I can do with Hazel to give me the result I hope for within what I have shown? I want a generic solution from traversing subdirectories, not hardwiring in a specific directory to cd to or with knowledge of actual paths. Appreciate your insights, thanks.

Re: Use of RAR archive correctly in subfolders with Hazel

PostPosted: Tue May 02, 2017 10:53 am
by Mr_Noodle
A full path is passed in via $1. Use the directory part of that.

Re: Use of RAR archive correctly in subfolders with Hazel

PostPosted: Tue May 02, 2017 3:13 pm
by rleaver152
Mr_Noodle wrote:A full path is passed in via $1. Use the directory part of that.


Thanks, this is the working solution:

Image

I think it may also help one of the other forum participants who wanted something similar to convert movie files in situ using a shell script