- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear friends
Is there any one know that how to check if a file is opened by another process?
I want to READ a file when the file is writing by another process with SHARE='DENYNONE' in OPEN statement.
It is sometimes OK but sometimes is NOT though both process has SHARE='DENYNONE'.
So, I would like to read the file after the writing process is done.
Please give me some comments.
Thanks a lot.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear friends
Is there any one know that how to check if a file is opened by another process?
I want to READ a file when the file is writing by another process with SHARE='DENYNONE' in OPEN statement.
It is sometimes OK but sometimes is NOT though both process has SHARE='DENYNONE'.
So, I would like to read the file after the writing process is done.
Please give me some comments.
Thanks a lot.
the Process which is writing probably should prevent any other process from accessing the file until it has finished - I think the risk of corrupting a file is high.
the process which needs to read the file probably should use DENYWR and put this into a timer loop until you the process successfully opens the file -- suggest also a maximum number of times this can occur before issuing a diagnostic error.
My 2c worth!
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... check if a file is opened by another process?
It's easy to do this using the Win32 API functions:
[cpp] ntry = 0
10 ihandl = CreateFile (fullpath, &
access, &
IOR(FILE_SHARE_READ,FILE_SHARE_WRITE), &
NULL_SECURITY_ATTRIBUTES, &
OPEN_ALWAYS, &
FILE_ATTRIBUTE_NORMAL, &
NULL )
IF (ihandl == INVALID_HANDLE_VALUE) THEN
IF (GetLastError() == ERROR_SHARING_VIOLATION) THEN
ntry = ntry + 1
IF (ntry > max_try) RETURN
CALL delay_ms (5)
GO TO 10
END IF
END IF
[/cpp]

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page