Solved

dos command to force file overwrite

Posted on 2008-10-02
5
11,147 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 84 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 84 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 95

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 84 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
move command 5 57
Meaning of "exceptions()" in "ist.exceptions( ist.exceptions() | ios_base:: badbit);" 3 67
Advice in Xamarin 21 79
Batch file or script with password 22 44
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

777 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