如何在不使用目录的情况下在磁盘上查找文件
How to find file on disk without use of directories
我正在编写一个 C++ 应用程序,它将监视以确保磁盘上的某些文件存在。我探索了 ReadDirectoryChanges 和 FindFirstFile/FindNextFile 函数以及一个简单的轮询解决方案。我的问题是,如果父目录的名称更改或文件被重命名,我无法判断。我不想查看文件的父目录以进行名称更改。有没有办法在不使用目录的情况下判断磁盘上是否存在文件?有人告诉我这可以使用 OS 本身的内存地址,但我没有找到任何东西。也许我只是不知道我在找什么?任何帮助将不胜感激。
Change Journals 可能是您要查找的内容:
An automatic backup application is one example of a program that must check for changes to the state of a volume to perform its task. The brute force method of checking for changes in directories or files is to scan the entire volume. However, this is often not an acceptable approach because of the decrease in system performance it would cause. Another method is for the application to register a directory notification (by calling the FindFirstChangeNotification or ReadDirectoryChangesW functions) for the directories to be backed up. This is more efficient than the first method, however, it requires that an application be running at all times. Also, if a large number of directories and files must be backed up, the amount of processing and memory overhead for such an application might also cause the operating system's performance to decrease.
To avoid these disadvantages, the NTFS file system maintains an update sequence number (USN) change journal. When any change is made to a file or directory in a volume, the USN change journal for that volume is updated with a description of the change and the name of the file or directory.
因此,您可以监控卷的更改日志记录以了解文件创建、文件名更改、文件移动、文件写入等,您将知道它们适用于哪些文件。
您可以使用 OpenFileById() function.
打开已知文件,通过文件 ID 或 GUID 识别
另请参阅 Raymond Chen 的博客 "If you want to use GUIDs to identify your files, then nobody's stopping you"。
我正在编写一个 C++ 应用程序,它将监视以确保磁盘上的某些文件存在。我探索了 ReadDirectoryChanges 和 FindFirstFile/FindNextFile 函数以及一个简单的轮询解决方案。我的问题是,如果父目录的名称更改或文件被重命名,我无法判断。我不想查看文件的父目录以进行名称更改。有没有办法在不使用目录的情况下判断磁盘上是否存在文件?有人告诉我这可以使用 OS 本身的内存地址,但我没有找到任何东西。也许我只是不知道我在找什么?任何帮助将不胜感激。
Change Journals 可能是您要查找的内容:
An automatic backup application is one example of a program that must check for changes to the state of a volume to perform its task. The brute force method of checking for changes in directories or files is to scan the entire volume. However, this is often not an acceptable approach because of the decrease in system performance it would cause. Another method is for the application to register a directory notification (by calling the FindFirstChangeNotification or ReadDirectoryChangesW functions) for the directories to be backed up. This is more efficient than the first method, however, it requires that an application be running at all times. Also, if a large number of directories and files must be backed up, the amount of processing and memory overhead for such an application might also cause the operating system's performance to decrease.
To avoid these disadvantages, the NTFS file system maintains an update sequence number (USN) change journal. When any change is made to a file or directory in a volume, the USN change journal for that volume is updated with a description of the change and the name of the file or directory.
因此,您可以监控卷的更改日志记录以了解文件创建、文件名更改、文件移动、文件写入等,您将知道它们适用于哪些文件。
您可以使用 OpenFileById() function.
打开已知文件,通过文件 ID 或 GUID 识别另请参阅 Raymond Chen 的博客 "If you want to use GUIDs to identify your files, then nobody's stopping you"。