I can't seem to find a solution for this.
I want to build a macro that copies a selected file to a certain location and if there's a file with the same name already there, just append "copy" automatically to the new file being copied.
So in both the source and destination I have "doc.txt" files.
When I move from source to destination, the doc.txt
being moved will become doc copy.txt
I found this, but this deals with sending the original file to the trash, which is not what I want to do:
I guess one solution would be to first save the source's file name as a variable, then compare it to all the items in the destination for a file with the same name and if TRUE, rename the source file to add "copy" and only then move the file.
If this is the only way, that's ok.
If there's another way, please share it ![:slight_smile: :slight_smile:](https://forum.keyboardmaestro.com/images/emoji/apple/slight_smile.png?v=12)
Yes, you can do that, or you can use the Create Unique File action.
1 Like
I'm a bit confused with that action...
I can see it creates a copy of the file inside the same folder, but I would like to move the selected file(s) to another folder and if there's another one with the same name, rename the selected file(s) being moved.
I was looking at the thread, but I can't see where this is mentioned (or maybe I'm not understanding what you guys are talking about, which is also possible)
It's a bit of a confusing one, for sure. You can use it to create a file with a unique name in your chosen destination folder, but that file will be blank. You can then delete that file and use the path it stores as a variable in order to do the file move.
However, there's no reason you can't use the first method you mentioned.
1 Like
Try this out:
COPY With Unique Filename (Subroutine).kmmacros (39 KB)
Macro screenshot
Here's an example of how to call the subroutine:
The benefit of this method is that you can create multiple copies which will be named incrementally:
![CleanShot 2023-05-20 at 10.19.43](https://forum.keyboardmaestro.com/uploads/default/original/3X/b/5/b5ff16f6dcad0dac3c4c2352ff9d4a30bb30aa6e.gif)
2 Likes
Thanks for sharing. I will have to look at this and see what's happening so I can fully understand the macro.
I need to take some time to do some research on this as well, as I still have a hard time when it comes to lists and all that, but I will get there.
Time to focus on making some music for now though ![:wink: :wink:](https://forum.keyboardmaestro.com/images/emoji/apple/wink.png?v=12)