TBH, I was running out "clean dialog" options -- because there are no proper radio buttons you'd need to put "Change", "Prepend" and "Append" in as checkboxes. Hmmm, perhaps you could do variables for each and, if blank, that operation doesn't happen.
And I assume by "Append" you mean "add between end of name and beginning of extension (if any)"? So
Pseudo-code for the renaming example, in case something concrete helps:
set Local_collection to contents of aFolder
for eachItem in Local_collection do
if eachItem is a directory then
do renaming on eachItem
do renaming on aFolder
So if you have
...and you call
myRename(dir1), the routine would look in folder
dir1 and see
subdir2. That's a folder, so
myRename(subdir2) would be called and would see
subdir3. That's also a folder, so
myRename(subdir3) is called.
At this point you have
subdir3 is a file, matching the
else of the
if, so is renamed. Finally
subdir3 is renamed and
myRename(subdir3) exits, returning "control" to
myRename(subdir2). So you know have
myRename(subdir2) then recurses any other folder in it's collection (none in this case) as above, renames all files, renames
subdir2, and exits. "Control" is returned to
"See a directory, dig down a level. See a file, process. Nothing left in there to process? Rename self, go back up a level, continue."
The two tricks here are:
a) Dig down first! That's what the
-d in the shell script
find command is there for. Otherwise you end up renaming any "child" directories before you process their contents and the previous paths to those contents are now invalid.
b) Have a "stop and return" condition in the function -- in our case it's "everything in Local_collection has been processed" -- else you'll get runaway recursion Luckily KM has a limit on the number of macro instances that can run at once, so you won't lock your machine up. (Unluckily that same limit will stop us from going more than ~24 folders deep -- each recursion seems to count as two "normal" instances -- unless you change a hidden preference from the default of "50".)