try
if( file.Attributes & FileAttributes.Hidden ==
        FileAttributes.Hidden )
{}

解决方案 »

  1.   

    The DirectoryInfo class offers a reasonable set of methods for creating, deleting, moving, and so on. For instance, we could create a new directory at some arbitrary location. (In the following example, the new directory is created within the current directory.) We could then create a subdirectory within the new directory, set and then get some attributes, and finally delete both the subdirectory and the newly created parent directory: dir = new DirectoryInfo("Foo");
    if (false == dir.Exists)
      dir.Create();DirectoryInfo dis = dir.CreateSubdirectory("Bar");
    dis.Attributes |= FileAttributes.Hidden | FileAttributes.Archive;Console.WriteLine("{0,-10}{1,-10}{2}", 
                      dis.Name, dis.Parent, dis.Attributes);dis.Delete(true);
    dir.Delete(true);The output follows: Bar       Foo       Hidden, Directory, Archive
      

  2.   

    文件和目录的属性是多样的,就是几个属性的结合。所以FileAttributes这个枚举的每一位都代表一个意义,如果文件的属性包含某个FileAttribute枚举所代表的位,那么它就有这个FileAttribute枚举所代表的属性。比如如果要判断某个目录是否为隐藏,就要先确定这个目录的属性里是否含有隐藏所表示的位:
    (DirectoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden