如何在 Windows 资源管理器中刷新文件的缩略图?

发布于 2024-09-15 17:47:14 字数 1694 浏览 4 评论 0原文

我们的 Windows 文件服务器安装了存档服务,可以“存根”在定义的时间段内未访问的文件。当对存根文件的请求发送到服务器时,存档服务会用原始文档替换存根并将其提供给用户。

关于存档服务的一个主要抱怨是照片的缩略图不再可用。我决定用 C# 创建一个程序,允许用户选择一个文件夹并取消存根其中的所有文件。它通过读取文件夹中每个文件的第一个字节来实现此目的:

if (Directory.Exists(path))
{
    DirectoryInfo di = new DirectoryInfo(path);
    FileInfo[] potentiallyStubbedFiles = di.GetFiles();
    foreach (FileInfo fi in potentiallyStubbedFiles)
    {
        //ignore Thumbs.db files
        if(!fi.Name.Equals("Thumbs.db"))
        {
            Console.WriteLine("Reading " + fi.Name);
            try
            {
                FileStream fs = File.Open(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.None);

                try
                {
                    //read the first byte of the file, forcing it to be unstubbed
                    byte[] firstByte = new byte[1];
                    fs.Read(firstByte, 0, 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An error occurred trying to read " + fi.Name + ":");
                }

                fs.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred trying to open " + fi.Name + ":");
            }
        }
    }
    Console.WriteLine("Finished reading files.");
}
else
{
    Console.WriteLine("\"" + path + "\" is not a valid directory.");
}

它运行良好,但我有一个小问题需要解决。

在 Windows 7 中,当 FileStream 关​​闭时,Windows 资源管理器会刷新文件并显示正确的缩略图,因此您可以看到每个文件未存根时的缩略图。然而,在 Windows XP 中,资源管理器在程序退出之前不会刷新文件,从而迫使用户等到所有文件都已取消存根才能浏览它们。

有没有办法强制 Windows XP 在读取文件后立即重新创建该文件的缩略图?程序关闭后发出什么信号来刷新文件?还是我完全以错误的方式处理这个问题?

Our Windows file server has an archive service installed that "stubs" files that have not been accessed for a defined period of time. When a request for the stubbed file is sent to the server, the archive service replaces the stub with the original document and serves it to the user.

A major complaint about the archive service was that thumbnails for photos were no longer available. I decided to create a program in C# that would allow the user to select a folder and unstub all the files in it. It does this by reading the first byte of each file in the folder:

if (Directory.Exists(path))
{
    DirectoryInfo di = new DirectoryInfo(path);
    FileInfo[] potentiallyStubbedFiles = di.GetFiles();
    foreach (FileInfo fi in potentiallyStubbedFiles)
    {
        //ignore Thumbs.db files
        if(!fi.Name.Equals("Thumbs.db"))
        {
            Console.WriteLine("Reading " + fi.Name);
            try
            {
                FileStream fs = File.Open(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.None);

                try
                {
                    //read the first byte of the file, forcing it to be unstubbed
                    byte[] firstByte = new byte[1];
                    fs.Read(firstByte, 0, 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An error occurred trying to read " + fi.Name + ":");
                }

                fs.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred trying to open " + fi.Name + ":");
            }
        }
    }
    Console.WriteLine("Finished reading files.");
}
else
{
    Console.WriteLine("\"" + path + "\" is not a valid directory.");
}

It works well, but I have one small problem that I would like to resolve.

In Windows 7, when the FileStream is closed, Windows Explorer refreshes the file and shows the correct thumbnail, so you can see the thumbnail of each file as they are unstubbed. In Windows XP, however, Explorer does not refresh the files until the program exits, forcing the user to wait until all files have been unstubbed before being able to browse them.

Is there any way to force Windows XP to recreate the thumbnail for the file immediately after reading it? What signal is being given to refresh the files after the program closes? Or am I going about this the wrong way completely?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘寄 2024-09-22 17:47:20

尝试使用 SHCNE_UPDATEITEM 进行 SHChangeNotify。

Try SHChangeNotify with SHCNE_UPDATEITEM.

浊酒尽余欢 2024-09-22 17:47:19

似乎没有与 Windows XP 的界面。 Vista及以上版本引入了IThumbnailCache接口。

你不能删除thumbs.db并强制它这样做吗?

拇指的格式没有记录,但是 http://vinetto.sourceforge.net/ 上有一个项目尝试如果你想深入了解它,可能会给你一些指导。

There doesn't appear to be an interface with Windows XP. Vista and above introduce the IThumbnailCache interface.

Could you not delete thumbs.db and force it that way?

The format of thumbs is undocumented but there's a project at http://vinetto.sourceforge.net/ that attempts to understand it that may give some pointers if you want to delve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文