Overwrite a read-only file in batch with xcopy
<p>We have an internal excel addon we deploy on a regular basis across a number of UNC directories. Each copy is set to read only so that the users can't alter it on accident. The "deployment" process involves going to each directory, and copying the file into the location with a click and drag. Since the file is read only there is no conflict, users shutdown the excel window and restart, they have the updates.</p>

<p>I've set out to replace this with a batch file that does it automatically as the number of directories continues to grow and there is occasionally an error such as forgetting to set the file to read only.</p>

<p>I'm using xcopy like so:</p>

<pre><code>xcopy "%workingdir%%filename%" "%uncpath%%targetdirectory%" /y /k
</code></pre>

<p>And I'm getting access denied on writing over the file. Is there a way to achieve this functionality that we get from click and drag using Batch? I'm certain that there must be a way to do it but all the solutions we've seen so far involve code to momentarily remove "Read Only" and then copy the file. I don't believe that is a viable solution as it may lock access to the file if someone is loading it at that split second.</p>

<p><strong>EDIT: Discovered moments after posting this that it is the xcopy flag /r
Not sure how I missed it, just one of those days I suppose. Thanks.</strong></p>