Guidance Forums / Reginald Rexx / Copyfile vs OPEN READ

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Copyfile vs OPEN READ
Posted by: Michael S 2012-01-30 14:19:36
I have a file I want to read - if I open it with OPEN READ I get an error message "The process cannot access the file because it is being used by another process." (fair enough, it is in use by another process).

HOWEVER.... if I copy the same file to a temp file and read that, all is well.

What I don't understand is, shouldn't the COPYFILE be reading it as well ? So, if that's correct, why doesn't that fail (or does copyfile use some different "open" that is even less intrusive than just OPEN READ) ????
Posted by: Jeff Glatt 2012-01-31 06:15:21
CopyFile calls a Windows OS function that does the copy. It reads the file with SHARED access, meaning that it doesn't deny anyone else from reading the file too. Of course, CopyFile fails if someone else has already denied access. The fact that CopyFile works should tell you that the other program did a SHARED open.

Stream()'s "OPEN READ" does not allow SHARED access. You're saying "I want to read the file, and prevent anyone else reading it at the same time". Of course, this fails because the other guy is already reading it. That's what the error is telling you here.

Change to Stream's "OPEN READ SHARED". (Or "OPEN BOTH SHARED").
Message3. Thanks Jeff
Posted by: Michael S 2012-01-31 21:40:08
Not sure I'd have noticed  that option even if it had been in the online help (correct me if I'm wrong, but I couldn't see it there. I could see open write shared/open both shared, but open read shared)
Message4. Tried your suggestion
Posted by: Michael S 2012-02-02 00:32:31
but it didn't work - received the same error message
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Fri 2024-7-19  Guidance Laboratory Inc. Hits:0