如何使用.NET更改windows文件夹上的隐藏属性

本文关键字:隐藏 属性 文件夹 windows 何使用 NET 更改 | 更新日期: 2023-09-27 18:26:13

如何更改现有文件夹的属性?

我必须使此文件夹和其中现有的所有文件可见。

C: ''文档和设置''%USER%''appdata

我发现了这个代码:

FileAttributes attributes = File.GetAttributes(@"C:'Documents and Settings'%user%'Dane aplikacji");
attributes = RemoveAttribute(attributes, FileAttributes.Hidden);

private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
    {
        return attributes & ~attributesToRemove;
    }

但它不起作用:(

谢谢!

如何使用.NET更改windows文件夹上的隐藏属性

在您的代码中,您只是在更新attributes变量,而不是实际更新文件的属性。

您需要使用File.SetAttributes('path', attributes)