Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Copyfile vs OPEN READ

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Copyfile vs OPEN READ
#13583
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) ????
Message2.
#13584
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
#13585
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
#13586
Posted by: Michael S 2012-02-02 00:32:31
but it didn't work - received the same error message
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sun 2024-10-6  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0