2011-09-28 14 views

答えて

7

File.SetAttributes()をご覧ください。それを使用する方法については、オンラインでたくさんの例があります。

FileAttributes attributes = File.GetAttributes(path); 

     if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) 
     { 
      // Show the file. 
      attributes = RemoveAttribute(attributes, FileAttributes.Hidden); 
      File.SetAttributes(path, attributes); 
      Console.WriteLine("The {0} file is no longer hidden.", path); 
     } 
     else 
     { 
      // Hide the file. 
      File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden); 
      Console.WriteLine("The {0} file is now hidden.", path); 
     } 
2

あなたがあるRemoveAttribute方法でコピーするのを忘れ:

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

属性(。JBの回答を参照してください)、または許可についてこれはMSDNのページがあることから撮影

、すなわち読み取り/書き込みアクセスなど?後者の場合は、File.SetAccessControlを参照してください。 MSDNから

// Get a FileSecurity object that represents the 
// current security settings. 
FileSecurity fSecurity = File.GetAccessControl(fileName); 

// Add the FileSystemAccessRule to the security settings. 
fSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType)); 

// Set the new access settings. 
File.SetAccessControl(fileName, fSecurity); 

は、より具体的な例のためHow to grant full permission to a file created by my application for ALL users?を参照してください。

元の質問では、FileSystemRights.Deleteの権利を許可しないように思えます。

関連する問題