File.SetAttributes() 无法按预期在 USB 密钥上工作

发布于 2024-12-28 13:38:46 字数 506 浏览 3 评论 0原文

FileAttributes attrs = File.GetAttributes( path);
File.SetAttributes( path, FileAttributes.Hidden );
attrs = File.GetAttributes( path);

此代码片段适用于我的 NTFS 文件系统 (C:\Temp...\whatever_file)。但是,当我尝试在 USB 闪存盘(FAT 文件系统)上执行相同的操作时,它从未成功设置隐藏属性。如果我在 Windows 资源管理器中手动设置它,则第一行会正确返回它已设置。但如果未设置,第三行(检查它)永远不会设置它。

谁能告诉我原因,我就免费赠送一只小狗。 :)

更新:当我说它不起作用时,我的意思是当我返回 Windows 资源管理器并查看该文件时,它没有设置隐藏属性。事实上,当我执行第二个 GetAttributes 时,它表明该位已设置。但在Windows资源管理器中它没有设置。即使我移除 USB 闪存盘并重新插入以确保其正确刷新。

FileAttributes attrs = File.GetAttributes( path);
File.SetAttributes( path, FileAttributes.Hidden );
attrs = File.GetAttributes( path);

This code snippet works on my NTFS file system (C:\Temp...\whatever_file). But when I try to perform this same operation on a USB key (FAT file system) it never successfully sets the Hidden attribute. If I manually set it in Windows Explorer, then the first line returns correctly that it is set. But the third line (checking it) never sets it if its not set.

I'll give a free puppy to whoever can tell me why. :)

UPDATE: When I say it doesn't work, I mean when I go back to Windows Explorer and look at the file it doesn't have the hidden attribute set. In fact, when I do the second GetAttributes it shows that the bit is set. But in Windows Explorer it is not set. Even if I remove the USB key and reinsert it to be sure it refreshes correctly.

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

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

发布评论

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

评论(1

终弃我 2025-01-04 13:38:46

感谢大家的输入,但我完全忽略了查看代码的其余部分,在其中我递归地关闭了我写入 USB 密钥的所有文件的只读属性,从而否定了我所做的一切前。

我在尘土和灰烬中忏悔。

Thank you all for your input, but I completely neglected to look at the REST of my code where I recursively turn off the read-only attribute on all of the files I've written to my USB key, thus negating whatever I'd done before.

I repent in dust and ashes.

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