Is the question whether you have already have the file open *in the same
Matlab session* ? If so then fopen('all') will give you the file
identifiers of all open files, and then fopen() applied to each file
identifier will give you information about the file. However, the
filename returned would be the same as the filename specified to the
fopen() statement, which would not include any directory information if
it was fopen()'d with just a relative path name. In such a case, there
is no Matlab provided method to determine the directory involved.
If the question is how to determine whether the file is open by _some_
process, then for Linux or Mac OS, you would have to call a program to
do the work for you. It might have to be a privileged program (after
all, the file might happen to be one you do not have access to.) On
Windows, you could test to see if the file exists and what its creation
time was, then try to fopen() the file for reading, and see whether that
is permitted; if it is permitted then the file was [probably] not open
elsewhere. If the fopen() fails, then as a safety measure, check to see
whether the file still exists and what its current creation time is: if
the creation time was before you started the fopen() but the fopen()
failed, then either you do not have permission or else the file was
busy. Or possibly you might be able to extract a "busy" status from the
"message" returned if you use the two-output form of fopen().
FYI, you can open the same file multiple times in ML:
fid1 = fopen('data.txt')
fid2 = fopen('data.txt')
fgetl(fid1)
fgetl(fid2) % returns the same line!
fclose all
So, perhaps, you should not bother too much about files being open in ML already. Or do you encounter specific problems?
As far as I know, there is no way ML can retrieve that information by itself.
Jos