Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tcl: retrive fileName from fileId

Status
Not open for further replies.

MarcoIppo

Programmer
Jun 9, 2010
3
0
0
IT
Hi,
I've developed a little script and I need to retrive FileName and FilePath from FileId.
I've opened a 'FilePath/FileName' file with 'open' command, and I've fileId of this opened file.
Now i'd like to retrieve, in another procedure, FilePath and Filename from memorized fileId.
It is possible using some info commands or similar?

thank you
Marco
 
I don't think so. You had to know the file name when you opened it. Why must you forget it?

_________________
Bob Rashkin
 
I'd like to write a driver that intercept a writing process to a file. Opening process is performed by a third part script and I have access only to fileId.
 
when you get a fileID back, it is not easy to tell from the ID anything about the file, it is more or less like a memory location. If you can somehow figure out the ending numbers on the fileID then you may be able to go and get the fileName, but from the fileID itself, I do not believe it is possible. Best of luck with it though
 
Hi

If you are on Unix or Unix-like operating system, it is trivial : you have it in the /proc.

Code:
[b]proc[/b] fileid2filename id [teal]\[/teal]
[teal]{[/teal]
  [b]return[/b] [teal][[/teal][b]file[/b] readlink [green][i]"/proc/[pid]/fd/[regsub {[/i][/green][lime][i]\D[/i][/lime][green][i]+} $id {}]"[/i][/green] [teal]][/teal]
[teal]}[/teal]

[b]set[/b] fileid [teal][[/teal][b]open[/b] unknown-file.name a[teal]][/teal]

[b]puts[/b] [teal][[/teal]fileid2filename [navy]$fileid[/navy][teal]][/teal]

[b]close[/b] [navy]$fileid[/navy]

Feherke.
 
A driver? :0| What are you trying to do? To monitor changes to a file, you don't really need a driver.

For example, in Windows you can interface to Operating System's supplied API to monitor file changes. I am new to Linux but I am pretty sure there are mechanisms to accomplish the same.

In quick search, I found this:

There maybe built in Linux commands so you don't even have to write C/C++ application.

Hope this helps.
 
Thank you all,
Unfortunately the script 'runs' on Windows.
Basically I want to create a script that will replace one esistenet (developed by third parties) that performs writes to files identified with his fileId. The script for 'third party' keeps 'open' the file being denied access to other processes. I would then intercept the write operation on file by running 'open - write - closing' file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top