I have no idea why you are getting a false from that just because some
other process has the file open. That makes little sense to me. Seems
like that ought to be an answer and that if this is accurately reported,
it would be a bug. A file doesn't cease to exist just because it is
open.
However...
Using an OPEN with status='new' will get you an error on many systems if
the file already exists. A caveat though is that on systems with file
versions (VAX VMS), it wil just create a new version.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
something like call system("dir [path_and_filename] > dirlist.txt")
and reading the result in dirlist.txt?
Then waiting a bit when the file is still around and repeat test?
Choose the commands according to your OS.
I'm not getting a false, I haven't coded this yet. Maybe I misinterpreted the
Intel help info:
ex
Is a scalar default logical variable that is assigned one of the following
values:
.TRUE.
If the specified file exists and can be opened, or if the specified unit exists
.FALSE.
If the specified file or unit does not exist or if the file exists but cannot
be opened
I was assuming that the file couldn't be opened if the other process had it open.
>
> However...
>
> Using an OPEN with status='new' will get you an error on many systems if
> the file already exists. A caveat though is that on systems with file
> versions (VAX VMS), it wil just create a new version.
>
I don't think I have to worry about VAXen.
That's certainly feasible, but a bit complicated.
It sounds like what Windows might do...
> I'm not getting a false, I haven't coded this yet.
> Maybe I misinterpreted the
You might check to see what it really does, but I agree that
sounds like what it might do. My best understanding is that other
programs can open the file for read, but not read/write, even if
the program doesn't actually plan to write to the file.
> Intel help info:
> ex
> Is a scalar default logical variable that is assigned one of
> the following values:
> .TRUE.
> If the specified file exists and can be opened, or if the specified
> unit exists
> .FALSE.
> If the specified file or unit does not exist or if the file
> exists but cannot be opened
> I was assuming that the file couldn't be opened if the other
> process had it open.
If you find the right OPEN parameters, such that it will create
a new file if it doesn't exist, won't overwrite the old one,
and will appropriately fail if someone else had it open for reading,
then you can do a sleep/open loop until it succeeds. Otherwise,
it seems that the problem is Windows specific and you need
Windows API calls to find out about the file.
>> However...
>> Using an OPEN with status='new' will get you an error on many systems if
>> the file already exists. A caveat though is that on systems with file
>> versions (VAX VMS), it wil just create a new version.
> I don't think I have to worry about VAXen.
VMS is still around, with new versions only for Alpha and Itanium.
-- glen
If INQUIRE does behave that way, perhaps:
OPEN( 10, FILE = filename, STATUS = 'OLD', ACTION = 'READ', IOSTAT =
ierr )
will help?
ierr should be unequal zero, if the file exists and can be read (you
should
be able to read it even if another process has opened it). Possibly
another
check (try open the file as new) is required to be fully certain it
does
not exist and the first check did not fail because the file could not
be
opened for reading only - this would solve the situation of versioned
files.
Regards,
Arjen
It's been my experience that many processes can open and use the same file (in different
spots) at the same time. Although, that was on a IBM SP. Maybe "can be opened" means the
user in question has read and/or write permission for the file?
FWIW, the following snippet from my "File_Utility" module shows the functions I use (since
2000/2001) to test for existence and open-ness. I've never had a problem with them on any
machine I've used (yet, at least :o)
INTERFACE File_Exists
MODULE PROCEDURE File_Unit_Exists
MODULE PROCEDURE File_Name_Exists
END INTERFACE File_Exists
INTERFACE File_Open
MODULE PROCEDURE File_Open_by_Unit
MODULE PROCEDURE File_Open_by_Name
END INTERFACE File_Open
CONTAINS
FUNCTION File_Unit_Exists( FileID ) RESULT( Existence )
INTEGER, INTENT(IN) :: FileID
LOGICAL :: Existence
INQUIRE( UNIT = FileID, EXIST = Existence )
END FUNCTION File_Unit_Exists
FUNCTION File_Name_Exists( Filename ) RESULT( Existence )
CHARACTER(*), INTENT(IN) :: Filename
LOGICAL :: Existence
INQUIRE( FILE = Filename, EXIST = Existence )
END FUNCTION File_Name_Exists
FUNCTION File_Open_by_Unit( FileID ) RESULT( Is_Open )
INTEGER, INTENT(IN) :: FileID
LOGICAL :: Is_Open
INQUIRE( UNIT = FileID, OPENED = Is_Open )
END FUNCTION File_Open_by_Unit
FUNCTION File_Open_by_Name( Filename ) RESULT( Is_Open )
CHARACTER(*), INTENT(IN) :: Filename
LOGICAL :: Is_Open
INQUIRE( FILE = Filename, OPENED = Is_Open )
END FUNCTION File_Open_by_Name
cheers,
paulv
I'm going to start with this approach, and stick with it until I have a problem.
I'll resort to this if the simple INQUIRE(EXIST..) fails.