James
James

Reputation: 753

How to find file location from fileID in MATLAB

Say I use fopen to generate a fileID:

fid = fopen('\some\path\to\toto.dat','r')

Is it possible to identify which file has been opened, solely from fid? For example,

fname = identify(fid);
disp(fname)
>> \some\path\to\toto.dat

Upvotes: 2

Views: 187

Answers (1)

verbatross
verbatross

Reputation: 607

Yes you can! The code is simply: fname = fopen(fid). You can obtain additional information including permission, machine format, and encoding as well. Documentation here: https://www.mathworks.com/help/matlab/ref/fopen.html

Upvotes: 5

Related Questions