Split Filename Into Parent-Child Folder Names?

I read this Lowercase all files selected in Finder quickly and it got me thinking about a problem I have. Could someone please help me with a KM macro?

I need to rename files to include their full paths, which may be several folders deep such as these…

folder/folder/file.ext
folder/folder/folder/folder/folder/file.ext
folder/folder/folder/file.ext

…become these…

folder-folder-file.ext
folder-folder-folder-folder-folder-file.ext
folder-folder-folder-file.ext

The separator isn’t fixed; it could be anything.

Then, in a separate macro, I need to convert those files back to folder and file names.

folder/folder/file.ext
folder/folder/folder/folder/folder/file.ext
folder/folder/folder/file.ext

I know For Each is the key, but I can’t figure out how to turn that key, so to speak.

Without regard to how to get this list of files, or what you do with the changed list. the below macro illustrates simply how to change the path separator into anything you want.

##Macro Library   [Files] Change File or Folder Separator in List [Example]


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/0/0f99716beac0e8bebc16db848b83e58d467f5557.kmmacros">[Files] Change File or Folder Separator in List [Example].kmmacros</a> (3.2 KB)

---

###ReleaseNotes

This macro is for illustration purposes only.  It is NOT a complete macro.

---

<img src="/uploads/default/original/2X/6/6023f7282aee1091fe0353c9c90140389024c565.png" width="640" height="972">