OK, so let's say I have a bunch of PNGs that could be an level deep within a directory. I want to find all those images and copy them to a new directory, but once they are in the same directory, there will be filename issues. As in:
Dir1
SubDir1
-File.png
SubDir2
-File.png
SubDir3
-File.png
SubDir4
-File.png
Dir2
SubDir1
-File.png
SubDir2
-File.png
SubDir3
-File.png
SubDir4
-File.png
Dir3
SubDir1
-File.png
SubDir2
-File.png
SubDir3
-File.png
SubDir4
-File.png
That's 12 files called File.png
I need to copy them, but I can't rename the original file, so how could I go about getting all these files, copying (and renaming - just appending an ID will be fine) into a new directory? Does anyone have a macro floating around that could do such a thing? Or close enough that I could amend it to suit my needs
Hopefully that will get you started. Try to develop your macro, and if you get stuck reply back with the specific question or issue you have (be sure to upload your macro. See How to upload your macro. Instructions for uploading to an existing post are just below the main instruction.
Well, I gave you an outline above, but since I'm stuck at home in Houston in sub-freezing temps, I had some time so I went ahead and built an example Macro for you.
You will need to test and modify or use to fit your specific workflow. But it should get you started.
Well, I get your current situation as I have a colleague in TX (Dallas) who gave up all hope of doing proper work yesterday. No power, no heating, no fun!
Thank you so much for this. I have made some slight adaptations to it and it's almost perfect, but there is just one tweak I'd like to make but am not sure if it's possible.
If you look at the results panel where you tested it on three files, note that the results are processed in the order SubFolder 1,then 3, then 2. I would like it to process it based on the order of those Subfolders. Instead of using a date stamp to make the resulting filenames unique, I had a variable that I increment by 1 each time.
However, the resulting files, e.g. file1.png, file2.png, file3.png actually relate to the files that wear in 1, 3, then 2.
Is there some kind of command that I can add somewhere to make sure that it processes in the order that the directory and subdirectories would appear in Finder?
Once again, thank you so much for your hep with this. Seeing how much is possible with KM makes me realise that I should try to really learn this in a structured way (any recommendations about that also welcome).
Thanks for this suggestion too. It has potential, but I would opt for appending an ID or similar, one because I know that the parent folder(s) will be quite long, which would result in some very long filenames in the final versions. But I'm going to store this one away for later use for something else
It appears that the Bash find command finds the files in the order the folders were created. As long as you always end each subfolder with digit(s), then this is easily solved by sorting the output of the find command. I have added that in my below update.
The reason I used the date/time stamp, rather than a seq number, is that if you later have the same subfolders that you wish to process again, then you will need to keep track of the seq number you use. This can be done using a KM Global Variable, but it seemed simpler to use the date/time stamp.
Having said that, I have changed the Macro to use the last digit(s) of the subfolder as the seq number. This will identify which subfolder it comes from, but does NOT deal with the above issue of future duplicates. If it were me, I'd do both: Seq number from the subfolder AND a date/time stamp. Your choice, of course.
So here's the update that addresses both of your issues:
Process in order of subfolder number
Use seq number from subfolder number
Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.
OK, I've got a 3rd version for you that does exactly what you want: FileSeq is calculated by incrementing a Global Variable for each file that is found.
To provide others with an example of the various methods for calculating FileSeq, I have left the other method in place, but disabled the Actions.
Example Output
Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.