name of file created by tmpfile()

View: New views
2 Messages — Rating Filter:   Alert me  

name of file created by tmpfile()

by Aditya Bhagwat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

Consider following code:

    [fid,msg] = tmpfile()
    fprintf(fid, "hello");

Is there any way of finding out the name of the file to which "hello"
has been written? I do know the file identifier (stored in fid), but
don't know the file name.

Regards and many thanks for your help,

Aditya
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: name of file created by tmpfile()

by Przemek Klosowski-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/23/2009 10:34 AM, Aditya Bhagwat wrote:
>      [fid,msg] = tmpfile()
>      fprintf(fid, "hello");
>
> Is there any way of finding out the name of the file to which "hello"
> has been written? I do know the file identifier (stored in fid), but
> don't know the file name.

If you want the name, use tmpname() and fopen(), for instance like this:
fopen(fname=tmpnam(),'w')

By the way, on Linux you can tease out the name of a file by the file
descriptor number:

system(['ls -l  /proc/$$/fd/' num2str(fid)])
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave