Windows 中的唯一文件标识符 [英] Unique file identifier in windows

查看:58
本文介绍了Windows 中的唯一文件标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在文件的生命周期内唯一标识文件(可能还有目录),而不管移动、重命名和内容修改如何?(Windows 2000 及更高版本).制作文件的副本应该为副本提供它自己的唯一标识符.

Is there are way to uniquely identify a file (and possibly directories) for the lifetime of the file regardless of moves, renames and content modifications? (Windows 2000 and later). Making a copy of a file should give the copy it's own unique identifier.

我的应用程序将各种元数据与单个文件相关联.如果文件被修改、重命名或移动,能够自动检测和更新文件关联会很有用.

My application associates various meta-data with individual files. If files are modified, renamed or moved it would be useful to be able to automatically detect and update file associations.

FileSystemWatcher 可以提供通知这些类型更改的事件,但是它使用一个内存缓冲区,如果许多文件系统事件快速发生,该缓冲区可以很容易地填充(并且事件丢失).

FileSystemWatcher can provide events that inform of these sorts of changes, however it uses a memory buffer that can be easily filled (and events lost) if many file system events occur quickly.

散列没有用,因为文件的内容可以改变,所以散列也会改变.

A hash is no use because the content of the file can change, and so the hash will change.

我曾想过使用文件创建日期,但在某些情况下这不会是唯一的(即复制多个文件时).

I had thought of using the file creation date, however there are a few situations where this will not be unique (ie. when multiple files are copied).

我还听说过 NTFS 中的文件 SID(安全 ID?),但我不确定这是否符合我的要求.

I've also heard of a file SID (security ID?) in NTFS, but I'm not sure if this would do what I'm looking for.

有什么想法吗?

推荐答案

如果您调用 GetFileInformationByHandle,您将在 BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low 中获得文件 ID.该索引在卷内是唯一的,即使您移动文件(在卷内)或重命名它也保持不变.

If you call GetFileInformationByHandle, you'll get a file ID in BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low. This index is unique within a volume, and stays the same even if you move the file (within the volume) or rename it.

如果您可以假设使用了 NTFS,您可能还需要考虑使用备用数据流来存储元数据.

If you can assume that NTFS is used, you may also want to consider using Alternate Data Streams to store the metadata.

这篇关于Windows 中的唯一文件标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆