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

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

(@gglick and @Tom, i forgot to tag you on the above, just wanted to make sure you get to see my additional question. thanks! -todd)

To keep the old file with the same name instead of trashing it, you need to modify the Split File action to save the file's base name (i.e. the name without the extension) and the extension into separate variables, to use them when renaming the existing file. There are, of course, any number of ways you could go about the renaming part, but I chose to use the ICU Date/Time token including milliseconds as a suffix coming after the original file's base name, so that you can move multiple files at once without any of them conflicting. The syntax used to rename a file to that looks like this:

%Local__DestinationFolder%/%Local__BaseName%_%ICUDateTime%yyyy-MM-dd-A%.%Local__Extension%

and the result looks like this:

[FILENAME]_2020-02-04-34569785.[EXT]

Here's the modified macro, with the actions that differ from the last version marked in yellow:

Move to Links Desktop Folder Without Replacing - from gabe glick.kmmacros (5.6 KB)

2 Likes

@gglick,

Omg this is great, and appending the files with the date+time is so smart... THANK YOU!

(I tried to do this macro myself before posting but after you explained what you did I see I never would have even had a chance lol)...

A question:

I didn't realize until testing, but is there a way to have this work on either a file OR a folder?

Or am I now getting too greedy lol.

With gratitude, -todd

You're welcome. Glad it's working well for you. I had to add another if/then action to the macro, but yes, there's a way to have this work on folders as well as files:

Move to Links Desktop Folder Without Replacing 1.1.kmmacros (6.8 KB) 1.1.kmmacros

2 Likes

@gglick this is great! i was trying to figure out how to do this but didn't know where to even begin lol. thank you very much, i love it!! -todd

1 Like