-3

I need something that can copy a specified file any and everywhere on my drive (or computer) where that file already exists; i.e. update a file. I tried to search this site, in case I'm not the first, and found this:

CMD command line: copy file to multiple locations at the same time

But not quite the same.

Example: Say I have a file called CurrentList.txt, and I have copies of it all over my hard drive.  But then I change it and I want all the copies to update.  So I want to copy the newer one over all the others.  It could 'copy if newer', but generally I know it's newer, so it could also just find every instance and copy over it.

I was originally going to use some kind of .bat file that would have to iterate over every folder seeking the file in question, but my batch file programming is limited/rusty.  Then I looked to see if xcopy could do it, but I don't think so...

For how I will use it most, I generally know where those files are going to be, so it actually might be as good or better if I could specify it to (using example), "copy CurrentList.txt, overwriting all other copies wherever found in the C:\Lists folder and all subfolders".

I would really like to be able to have it in a context menu, so I could (from a file explorer) right click on a file or selected files and choose the option to distribute it.

Thanks in advance for any ideas.

  • 1
    What code have you written already? Please have a read of [this guide on producing code for a good quality question](https://stackoverflow.com/help/minimal-reproducible-example), then include and mark up your code in your question. Cheers! – Joundill May 20 '20 at 00:12
  • Try checking `find /?` and `findstr /?` – Nico Nekoru May 20 '20 at 01:56

1 Answers1

2

Use the "replace" command...

replace CurrentList.txt C:\Lists /s
  • Thank you! I should have been aware of that. I know I can make that into a batch file, something like: "replace %1 C:\Lists /s". But is there a way to integrate it into a context menu such that the filename variable would be sent to the batch file? – Ash Woods May 20 '20 at 05:42
  • After attempting that, I got "Extended Error 32". I presume this happened because it was trying to replace a file with itself. Maybe I should have mentioned that the file will originate from a subfolder of C:\Lists.. Actually, I see that using the /u option is a fair work-around for the error. – Ash Woods May 20 '20 at 05:47
  • You can ignore that "Extended Error 32". You'll get then when you try to replace files in a folder and the "source file" is located in that folder as well. All the other files will still be replaced even when you get that error. – AppetiteForDestruction May 20 '20 at 08:36
  • Actually no, error 32 interrupted the batch. But the /u option worked fine. – Ash Woods May 20 '20 at 14:00
  • Add the /U switch if the source file (and latest version) is in the directories. – Bob Baeck Aug 20 '21 at 12:43