Link to home
Start Free TrialLog in
Avatar of Robert Berke
Robert BerkeFlag for United States of America

asked on

does windows 7 pro DOS COPY command overwrite open files?

my batch file has a command like    Copy File1 File2 /y

File 2 is an Access Data Base that is open.

I always thought copying to an open file would give Access Denied, but that does not seem to be the case.  

Both of my computers let the copy go forward with no warning which leads to data base corruption on the target file.

So, is this normal ???
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you remove /Y, it will prompt. I do not use /Y and it always prompts for any copy.
Avatar of Robert Berke

ASKER

The batch file in question refreshes a client PC so its Front End.mdb database has the most recent copy from the server.  The old version ALWAYS exists.  

I need the batch file to say
if not OPEN "\\server\share\whatever.ldb" copy "\\server\source\whatever.mdb" "\\server\share\whatever.mdb" /y
So your LDB idea would work, but what about a more general case where the file is open but does not have something like a ldb locking file?
You asked why no warning and /Y is why no warning. If you  are happy with no warning, use /Y. You suggested you were not happy with no warning so do not use /Y.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was about to post my research when I saw Qlemo's post.  He and I are pretty much in agreement that database files are special cases that are not "Copy protected" at all (the /y  switch is completely ignored.)  It is not quite the same as a Notepad file. Notepad files are totally unlocked, and their name can be changed even while they are open.  But an open mdb file cannot have its name change.  

It is my belief that things were handled differently in XP, and that the MDBs were "copy protected" but I could be wrong – but I don’t have a windows XP machine to handy to test

I'll award points now.

Since I had already drafted my research, I am posting it below. It has a few minor additions that might be useful to future researchers.  


Further testing reveals that we were on the wrong track about the Copy program. The Windows Copy command protects most open files to prevent accidental destruction and the /Y parameter does NOT override that protection. (I tested it Excel, Word, project.Otm and all of those are protected.  I also tested it on .txt files that were opened with vba open update. None of these could be overwritten; they all got this error message:

  “The process cannot access the file because it is being used by another process.”

But Windows 7 Copy handles .mdb files totally differently. When working on an MDB the Copy function does not protect the target at all.  The /y switch is ignored.  The locking status is ignored.  Some other windows functions like Explorer Rename still provide protection.

Does anybody have any specific knowledge about that?  Ideally a pointer to MS documentation?
It turns out that XP works the same as windows 7.

Copy file1.mdb to file2.mdb  will never say "Overwrite c:\aaatmp\file2.xls? (Yes/No/All):
and, it will never say  “The process cannot access the file because it is being used by another process.”

Somehow I never noticed this quirk about .mdb files in Windows XP and Windows 7.  It turns out that I have several "production" batch files that I thought were working, but now know to be unsafe.  Perhaps that explains why we have occasional mdb corruption.

I will fix the batch files by using NVIT's trick  "if not exist "\\server\share\whatever.ldb" copy "\\server\source\whatever.mdb" "\\server\share\whatever.mdb" /y.

 Of course, we now know that the /y flag is ignored for mdb files, so I will leave it off when I fix those batch files.