Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dos command to force file overwrite

Posted on 2008-10-02
5
Medium Priority
?
12,684 Views
Last Modified: 2012-06-21
her is my problem, I trying to write a batch file that will overwrite a a file by another.
the syntax that i got is
copy file1 file2 /y

simple enough eh? Only I'm getting Access denied.
How do I force the copy?
Or How do I put credentials in the batch file so the command works?
Or Is the away to use batch files to impersonate a user?
0
Comment
Question by:the_bachelor
5 Comments
 
LVL 7

Assisted Solution

by:johnny_the_knife
johnny_the_knife earned 336 total points
ID: 22629342
If you are running on Windows, you can use RunAs to execute commands in the context of another account.  This article provides the information you will need:

http://www.ss64.com/nt/runas.html
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 336 total points
ID: 22629354
If the file is in use, you may not be able to - not without closing/terminating the access to the file....

You might try using robocopy.  Add the /b switch to put the copy in 'backup' mode...
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 22629404
runas will not permit you to store authentication information.  If you are not an administrator then you may not be able to overwrite the file.
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 336 total points
ID: 22724185
Simple.... Sounds like you're trying to copy over a read-only file.

Use DOS's XCOPY instead of COPY, ie:

    XCOPY source destination /R /C /Y

Easy Peasey !! But most importantly, use the /R switch allows you to overwrite read-only files.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question