Re: figuring out a filename from it's handle...



On Aug 30, 4:53 pm, daneyu...@xxxxxxxxx wrote:
If I've lost track of a filename that a channel was opened for, is
there a way to get the filename from just the channel name?

In other words, after doing the following:

set file_handle [open $filename r]

can I then use $file_handle to determine $filename?

-Daniel

just override your open call to creat an array of file descriptors
and their associated filenamss, or what not. Overload close to remove
from the global array

global fd2filename
array set { stdin stdin stdout stdout stderr stderr }

rename open Open
proc open { args } {
global fd2filename
set fname { lindex $args 0 ]
set fd [ eval Open $args ]
set fd2filename($fd) $filename
return $fd;
}
..... do same thing for close except you remove
the array index from the global array and when
you want to find out what the filename is you
merely

set fd [ open /tmp/log.file "r" 0660 ]
puts "filename for fd is $fd2filename($fd)"

I probably forgot something as I did not test this
out but it should work.

Carl

.



Relevant Pages

  • Re: Help end the testing tedium please
    ... When you call it from Consolidate ... Please assume that both the filename and the ... worksheet name are sequential. ... the file really were test1 thru test60, would the array statement need ...
    (microsoft.public.excel.programming)
  • Re: Help end the testing tedium please
    ... When you call it from Consolidate ... Please assume that both the filename and the ... the file really were test1 thru test60, would the array statement need ... With Selection ...
    (microsoft.public.excel.programming)
  • Re: (Steve) Iterate files to determine latest and then kill others
    ... Declare an array to hold filenames ... Filename = Dir$ ... declare the array as long instead and stuff it with the rightmost ... > 'Get version number of main ppa file ...
    (microsoft.public.powerpoint)
  • Re: request for code review
    ... > changing the size of the array. ... char large enough to hold the LONGEST FILENAME STRING that the ...
    (comp.lang.c)
  • Re: request for code review
    ... > changing the size of the array. ... char large enough to hold the LONGEST FILENAME STRING that the ...
    (comp.lang.c)