How to Create a Button to Copy, Delete, and Replace a File in Place

Here's a strange request:

I have some Windows shortcuts whose icons periodically disappear from the Start Menu, and the fix (such as it is) is to delete and recreate the shortcuts. I have to copy them first, then delete the originals, then give the copies the same name as the originals. I don't have to do this often, but it's the kind of thing I'm used to being able to do in Opus with a single button.

So how do I arrange the commands in a button to:

  1. take a selection of files and get their file names
  2. copy those files in plac
  3. delete the originals
  4. select the copies
  5. rename the copies to the same names the originals had

(?)

In my folder are four files I want to perform this operation on and two I want to leave unmolested. So I'd like the button to operate on multiple selected files while leaving unselected files unchanged.

Is that doable? Is it as simple as I think it should be? Or have I really stumbled onto a weird edge case that's trickier than usual? (I suspect I'm just missing something obvious.)

Something like this should do it:

Copy DUPLICATE AS *_COPYFIXTEMP
Delete QUIET NORECYCLE 
Rename FROM *_COPYFIXTEMP TO *

Clearing the Windows icon cache usually fixes that kind of problem as well.

Faster than I could restart from a Windows update! :open_mouth:

I had been trying this:

@nofilenamequoting
cd {sourcepath}
Copy "{file$}" AS "{file$}.TEMP" QUIET
Delete "{file$}" QUIET
Rename "{file$}.TEMP" AS "{file$}"

... but trimmed back to this with your guidance:

Copy DUPLICATE AS "{file$}.TEMP"
Delete QUIET NORECYCLE 
Rename FROM "{file$}.TEMP" TO "{file$}"

... it works like a charm.

'Preciate the heads-up there, as well, but that's never done the trick in this particular instance.

It's an app that installs the user profile path by default, and I suspect it tries to replace the icon on updating when the icon library it points to isn't yet available. I would think recreating the iconcache.db file would indeed fix it, but it never seems to. Deleting and recreating the icon, however, does. ¯_(ツ)_/¯

Most of the guides about how to delete the icon cache are wrong, fwiw.

Interesting. I usually queue up a delete of iconcache.db using a tool called The Avenger so that it happens on my next startup.

If you happen to stumble across a good set of directions and if you happen to think about me when you do, feel free to share here. I'd appreciate it (but I'm getting along without, so please don't invest any actual effort).

As a follow-up question, is there a command to build a delay into a button? (If, for example, I wanted to see the rename and delete here happening.)

I wrote a tool many years ago to clear the icon cache on Vista and it still works well for me on Windows 10:

(Beware that some garbage anti-virus tools think it is a virus and/or block it from working, despite it coming with source code, not doing anything strange and not changing in 10 years. But that's a reason to replace bad anti-virus with something better. :slight_smile: I've given up reporting the false-positive to the bad anti-virus vendors after having to do it more than once for the same vendor.)

The scripting API has a delay function you can use. There isn't anything built-in for simple non-scripting commands, although there are various kludges people use for .bat files which can be used. I'd go with the scripting method since it's more explicit and not much extra typing.