Move file from sub folder

Hi Everyone, I have a folder that contains multiple sub folders with each sub folder containins 2 files. Both of the files have different extensions with one extension being .WAV and the other being .hprj. I want to move each .WAV file up a directory into the parent folder and then delete the sub folder. One done I will have 1 folder that contains multiple .WAV files only. I have tried to search for a solution around the forum and it appears that this can be achieved by using a For Each but my KM skills are not great and I am therefore looking for some help :slightly_smiling_face:

I have attached a picture of the parent folder that contains the sub folders (ZOOM0001,ZOOM0002 etc.) and also a picture of the contents of folder Zoom0001 (that contains the two sub files). The main parent folder is named FOLDER01. Thank you in advance for any help :grin:


Sub Folder contents

Your question seems quite clear to me. However you didn't say if this is something you are trying to accomplish just once or many times into the future.

Personally, I wouldn't use KM to solve this. I think it can be easily done with one or two shell commands. I suppose you could place these two shell commands into a KM action if you want to.

Let me ponder the shell command solution now. I'm a little rusty with shell commands, but I can always read the man pages and find solutions.

Okay, there are three very simple steps to solve this using a shell, such as a Terminal window shell or a KM Execute Shell script action.

  1. Change your directory to the full path of the FOLDER001 directory. (eg, "cd ~/Folder001" or whatever path your folder is found at.)
  2. Move all the WAV files from the subfolders to their parent folders with this command: "mv ZOOM*/*.WAV ."
  3. Delete all the subfolders and their contents using a single command. I hesitate to provide that simple command because I need to be confident that you will not accidentally delete other files that you need. I can give you the command if you insist on it, and are satisfied with this approach.
1 Like

As @Airy I would probably also not use KM for this myself. If I didn’t need it as part of a larger routine or something like that I think I’d probably just do a Finder search in the folder for ".WAV", and drag the search result up one directory, or something like that. Another reason not to use KM here is that an automation routine involving deleting directories can be very destructive.

But anyways, heres one way you could go about solving this within KM. I've here used the Move to Trash action, instead of the Delete Directory action, as it have less destructive potential. As I know that these ZOOM-folders can contain more than one .WAV-file per recording (depending on your recorder’s settings), I added the second For Each so that this macro can also handles more than the described one .WAV file per subfolder.

You'd need to add the path of your FOLDER01 directory to the local__parentPath Set Variable action for it to work. You can get this path by right clicking on your folder, pressing ⌥ option, ㅤㅤand then selecting Copy "FOLDER01" as Pathname.

Move file from sub folder — TEST.kmmacros (19 KB)

Macro Image

1 Like

Here's a version that acts on either a selected folder -- you'd select "FOLDER01" in the above example -- or, if nothing is selected, treats the currently-open folder in the Finder as the parent (as in the screenshot above). You may prefer to change that bit to a "Prompt for folder" for explicit control over what you target -- if so, disable the first action and enable the second.

Using recursion on the first "For Each" means it will handle multiple .wavs in a folder and, if Zoom uses such a structure for recordings, subfolders. If Zoom does use subfolders we may need to add some conflict resolution when moving the files!

Once the files are moved we just "For Each" again, trashing anything that's a folder.

Move WAVs Up.kmmacros (8.1 KB)

Image

2 Likes

That solved it Thank you very much for your help.

Thank you very much for your help : )

Thank you for your help and explanation :slightly_smiling_face: