Get folder contents and move it

Hi Everyone,

I am trying to do get the contents of a folder that is within a parent folder and then move the contents. The problem is that the folder contained within the parent folder does not have a fixed name and therefore I cannot set the path in KM because it will always be different! So for example my string may be ~/Desktop/Booking Files/New/Floorplan/High Street/random files or it might be ~/Desktop/Booking Files/New/Floorplan/Low Street/random files. So only part of the string (~/Desktop/Booking Files/New/Floorplan/ ) is going to be the same each time. I can tell KM to get most of the string but am not sure how it will get into the next folder? So in my example image I can set a path to get me into most of the folders but not all the way as the one named Random Name has a name that will change all of the time! I need to get into the Random name folder, get the files from inside and then put them onto my desktop. Hopefully this makes sense...

Thank you in advance for any help :slightly_smiling_face:

The Copy a File and Move or Rename a File actions do not support wildcards.

It would be easy to substitute an Execute Shell Script action containing a unix mv command, which does support wildcards [^1]. Unfortunately it would also be easy to overwrite files and have other unforseen side-effects, so I wouldn't recommend that approach.

I think you might be better off automating this task with the application Hazel, which you could set up to move all files in all subfolders. [^2]

[^1]: "The character * is called a wildcard, and will match against none or more character(s) in a file (or directory) name." - Unix: Wildcards

[^2] Processing Subfolders – Noodlesoft

Ah ok. I have Hazel installed but wanted to do this just with KM. As a "work around" would it be possible to some how get the contents of the folder named Floorplan (which would be the randomly named folder) and then rename it? That was I would have a string that would take me straight into the new renamed folder enabling me to work on the contents? So for example my I would tell KM to get the folder contents of the Floorplan folder and rename the folder inside of it to Floorplan Files. My path would then be ~Desktop/Booking Files/New/Floorplan/Floorplan Files/ that would put me inside of the folder and from there I could move the files to my desktop? I have tried to do this with a For Each Item in a Collection Execute Actions but of course I could not get it to work as I am not very experienced with KM (yet!).
Thank you for your help :grin:

1 Like

I have found a work around and am posting it here to hopefully help someone else some day. It may not (probably is not) the best way but it seems to work for me:

Hopefully someone will find this helpful :slightly_smiling_face:

There is a simpler solution which doesn't require renaming folders.

Assuming there is only one folder (whose name you do not know) to be found in the first For Each Loop, the Variable LOCAL__WildCardFolder will hold the path to that folder after the loop is finished. (The loop does nothing except get the path to the random named folder.)

You can then use that Variable, LOCAL__WildCardFolder as the path to the files you want to move (and delete the folder at LOCAL__WildCardFolder if you want to).

EXAMPLE Move files out of WildCard Folder.kmmacros (3.6 KB)

1 Like

Brilliant, thank you very much this is great. I will update my version as this is basically better :grin:

1 Like