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

查看:1115
本文介绍了在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).

我还听说过一个文件的SID(安全ID?)在NTFS的,但我不知道这是否会做我在寻找什么。

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.

任何想法?

推荐答案

如果你调用<一个href="http://msdn.microsoft.com/en-us/library/aa364952%28VS.85%29.aspx">GetFileInformationByHandle,你会得到BY_HANDLE_FILE_INFORMATION.nFileIndexHigh /低文件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天全站免登陆