Move a File to a Folder and Replace Same-Named File

Hi,

I have a macro that moves a copy of a selected file to a folder, is there a way I can bypass the KM dialog saying it can't do that because the file already exists in the folder? (I often make changes to an art file and update the linked image in my indesign document by replacing the older same-named version).

I've attached a screenshot of the current macro, and I've also included the actual macro.

Thanks for any help on this!
-todd

move to links desktop folder.kmmacros (3.8 KB)

try adding a Delete a File action

hi, thank you... do you know how i would integrate a "delete a file" action into my macro? (someone made that macro for me, it was beyond my skillset). thanks! -todd

Here's one way you might go about that:

Move to Links Desktop Folder.kmmacros (4.8 KB)

thank you gabe (!) but it doesn't seem to work for me... first i see a click in the very upper left of my screen, then i get a dialog saying "action failed because destination already exists..." :frowning:

Oh, right, I left the mouse clicking action to the default upper left corner rather than the current mouse position. Try changing this:

to this:

thanks gabe! – i tried it but still got the "action failed because destination already exists..." ?

I'm not sure what to tell you then, because it works fine for me. What happens if you use the macro on a file that you're sure does not exist in the destination folder?

good question: it moved a new file that does not exist in the destination folder just fine. but it still won't move one in that already exists :frowning:

Sounds like the Trash File action isn't working then, for some reason. What happens if you enter a file path in the Trash File action manually and run just that action, like this?

You can even drag the test file into that field directly, to make entering the path easier. Just make sure to use a file you don't mind deleting.

That didn't work, Gabe.

Mmmm: I wish I could be more proactive in helping on this but I'm a bit outta my league with understanding how this macro is even working :slight_smile:

Well, at least that makes it clear that the Trash File action is what's failing, but I'm still at a loss as to why that would fail while the Move File action works fine. At this point, the only thing I can think of is to try the Interactive Help option from the KM Editor's Help menu, select "Something expected is not happening," and see if that clears anything up.

Thanks Gabe!

I use Trash File “/Volumes/External HD /sims 2 backup/The Sims 2”

and this works fine it puts the folder "The Sims 2" into the trash. I use it daily with Version 9.0.4, check your version maybe?

Hi Dennis,

Thanks for the input, I also have version 9.0.4... do you know how I'd be able to move a file into another folder instead of the trash and if the file is already there I wouldn't get the KM dialog saying it can't do that cause the file is already there?

Thanks!

-todd

The thing is that the “Move or Rename a File” action does not have an option “silently overwrite existing files at the destination”.

So, you have only two possible solutions:

  • Use a different action for moving the file (for example a shell script action with mv -f).
  • Get rid of the old file at the destination before moving the new one there. That is: Trashing the old file with help of the Trash File action before moving the new one.

Since you are probably in an early learning stage with KM, you really should go for the second solution.

@gglick showed you with his macro how to do it. Then you found out that for some reason the Trash File action doesn’t work on your machine – even when you’re testing it in isolated conditions.

So I would say, this is a pretty priority thing to find out, why isn’t the Trash File action working. This is a very basic action and you will need it also for other macros.

And, once the Trash File action works, the whole macro will most likely work.

When you tested the standalone Trash File action, have you double-checked if path and file name for the test file are correct? Any typos maybe?

3 Likes

hi @Tom, thank you! (and thank you @gglick ) i retested the standalone trash file action and IT WORKED this time! i must have been doing something wrong last time...

but then when i tried the whole macro again, the action still failed with the dialog saying "destination already exists..."

any thoughts on where i can go from here? i wish i better understood how it works so i can be more proactive in helping with this :frowning:

here's the macro (i clicked "option" at the first step because i want to move a copy of the file into my "Links" folder):

Move to Links Desktop Folder - from gabe glick.kmmacros (4.7 KB)

thank you!! -todd

You're welcome, @toddlerner.

Fortunately, I think I figured it out. For some reason, the version of the macro you were using had a variable containing the full file path (Local__FileToMove) where it should have used the one that only contained the file's name (Local__FileName). I got the same "file already exists" error when I tried it with the version you were using, but fixing the variables being used seems to have done the trick. Now that your Trash File action is working properly, this should work for you:

Move to Links Desktop Folder - from gabe glick 1.1.kmmacros (5.2 KB)

By the way, if the reason you had the first action option-click rather than normal click was to have the file be copied rather than moved, I'm afraid that wouldn't work, since KM isn't moving or copying the file by dragging it the way we would manually. You used the word "move" in your OP and this thread's title, so I assumed you wanted to move rather than copy, but if you do just want to copy, the answer isn't to change the mouse click action, but the file one at the bottom:

One other change I made to this version is to add a notification at the end, so if that shows up, you'll know the macro ran successfully without needing to check the copied file(s).

1 Like

Omg @gglick it works now!

Hahaha about me having the first action option-click – I don't know what I'm doing, thank you thank you for catching that, and sorry I messed up the move to trash test.

I SO appreciate you staying with me on this and helping me. I LOVE my new macro. and thanks for the notification bonus :grinning:

And @Tom thank you (!) also for your help on this, I was about to give up on trying to have it work and I'm so happy now. I love KM and macros that help streamline my workflow :grinning:

With lots of appreciation,
-todd

2 Likes

A question:

How might I modify the above macro for a different usage where I want to move (not copy this time) a file to a folder but if a file with the same name already exists there I want to keep them both (I don't care how the new or old file's name is appended to pull this off). Also, I might in the future want to move a third or fourth file with the same name into this folder.

(What I need this for: instead of always tossing everything into the trash, I have a folder named "x" where I instead move things, just in case I might need them in the future, and once a year or so I toss old files from this folder... but sometimes there's already a file in there with the same name so I'd like to keep both that and the new one I'm moving into the folder)

Thank you!

-todd