2

Is it possible to access a file in Windows Explorer or MS-DOS using the unique file ID only? I was thinking that I could type in something like {FILE_ID.VOLUME} ex. {2319237819273897.1} and the file c:\temp\myfile.txt would open. This feature could be useful to access a file that has been moved to a different directory as the unique file ID remains the same after the file has moved (even multiple times), and remains the same until the file is deleted.

1
  • 2
    MS-DOS is unlikely to be relevant to your question, unless you're dual-booting. Did you mean the Windows command line interface? Also, the file IDs discussed in the link don't necessarily remain the same from the user's point of view, because many applications modify a file by deleting it and creating a new one. From the user's point of view, it's the same file, but as far as NTFS is concerned it's a different one. Commented Feb 1, 2015 at 0:40

1 Answer 1

1

This depends on the filesystem. FAT doesn't have file IDs, but in Windows low-level API there are mechanisms to open the file by its unique ID. It is up to the filesystem driver how to treat this ID -- FAT generates the ID dynamically, while NTFS works with unique file IDs in some way (I don't know the details though).

File ID support has been added to Windows for compatibility with certain Unix stuff and this is not a widely used feature. I don't know if you can use it via Win32 API (and so from Explorer).

Update: Thanks to Harry Johnston in the comments now I know that you can open the file using OpenFileById WinAPI function which appeared in Vista.

Sign up to request clarification or add additional context in comments.

5 Comments

From Windows Internals: "In addition to storing the object ID assigned to a file or directory [...], NTFS also keeps the correspondence between object IDs and their file reference numbers in the $O index [...]. The index collates entries by object ID, making it easy for NTFS to quickly locate a file based on its ID. This feature allows applications, using undocumented native API functionality, to open a file or directory using its object ID." You are correct, it is possible to access a file in an NTFS volume using its ID, but it is not readily available through the Windows API.
@IInspectable: that used to be true, but I believe it is out of date: OpenFileById
@Harry: Thanks for the correction. Do you happen to know whether the API is capable of working with FAT volumes, or is this NTFS/ReFS only? In case someone is interested, the 128-bit file ID can be obtained with a call to GetFileInformationByHandleEx passing a FileIdInfo file information class value (Win 8, Server 2012). The 64-bit file ID can be obtained with a call to GetFileInformationByHandle.
@IInspectable: I don't know, but I think only NTFS/ReFS. FAT doesn't have file IDs per se, the closest thing available is the identifier for the first cluster and that changes during defragmentation. Note also than on NTFS you can enumerate file IDs by reading the MFT via FSCTL_ENUM_USN_DATA and related functions. This is a lot faster than iterating through the directory tree, and is probably the scenario where OpenFileById() is most useful. (I assume ReFS has a similar mechanism but I've never investigated.)
@IInspectable You also have the NTFS $OBJECT_ID attribute for each file, stored in the Master File Table I believe: Type 0x40 -- specifies an ID that allows tracking the file in the event if its name or location changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.