Filename from file pointer




















Microsoft does that a lot. And it might even be faster. Yes, but is there only one name and path for that file? I thought Windows had long and short names for just about every file and directory, therefore making many names for the same file very common. Possible, maybe, fast, unlikely, portably, no chance.

If you don't insist on a unique filename, just at least one that works when running with Administrator privilege, probably. Does your compiler have stat for Windows? My guess is that it probably does. Does your compiler have something that can do the equivalent of stat on an open stream? A bit less obvious, but probably available. This I am not sure about. You're trying to match these numbers from fstat on the open stream against stat on files in the filesystem to find a match.

If they are dummy, forget it, many unrelated files will match. How long does it take for you to get Windows to scan your whole hard disk to look for files of a particular type using, for example, the Windows "Find a File" GUI? This is probably how long a full tree-walk will take. Is this acceptable speed?

On a bare-bones Windows XP system just about the only application installed or ever used is Windows Update with about 8GB of disk space, this took 5 minutes certainly unacceptable for a Web application. Maybe no problem for a batch job. How much this takes on your system will depend on whether your disk is bigger than your processor or vice versa. Dik T. You have gotten your C answer. It can not be done in standard C.

Whether it is possible on your platform is a different question, and that is indeed a Windows question, so platform dependent. Kenneth Brody. I know there is some way under Windows to go from handle to filename, as I have utilities that display all open files in a process, including the handle and filename, among other information.

However, this is highly Windows-specific. The user does not need to Know the details, because the definitions obtained from stdio. Opening a file: The fopen function opens a stream for use and links a file with that stream. A file pointer associated with that file is then returned by the fopen function. Most often the file is a disk file. Another parameter is a pointer to a string, name mode, determines how the file can be opened.

The below table shows the valid modes in which a file may be opened. As can be seen from above table, the files can be opened in the text or the binary mode. If an error occurs when the fopen function is opening a file, it returns a null pointer. When a file is opened in read mode, three important tasks are performed by fopen. A search is carried out on the disk for the file to be opened. If the file is found, it is loaded into memory from the disk. In case the file is too large, then the file is loaded partwise.

In case the file is not found, a NULL is returned by fopen. The character pointer is a part of FILE structure and points to the first character in memory where the file is loaded. If a file is opened using the above method, fopen detects any error in opening a file, such as a write-protected or a full disk, before attempting to write to it. A null is used to indicate failure because no file pointer will ever have that value. If a file is opened foe writing, any pre-exiting file with that name will be overwritten.

This is because when a file is opened in a write mode, a new file is created. However, if it does not exist, it will be created. Closing a File: As said earlier, there is usually a limit on the number of files that can be opened at one time, and so it is important to close the file once it has been used.

Create Path object from given string i. To get the file name without extension all the filename function on path i. Your email address will not be published. This site uses Akismet to reduce spam. Learn how your comment data is processed.



0コメント

  • 1000 / 1000