FileAttributes
-
I copy a "ReadOnly" file. I change it's name and then go to delete it. Problem it won't delete because it is ReadOnly (At least when I remove ReadOnly it deletes fine). This is the error I receive: ERROR in test System.UnauthorizedAccessException: Access to the path "c:\test\\test.dll" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.File.Delete(String path) at Check.RunTest.DoRun(String path) in c:\project\runtest.cs:line 38 Here is my code: try { string[] testfiles = Directory.GetFiles(path); foreach( string testfile in testfiles) { string testFolderName = path + @"\" + Path.GetFileName(testfile); //Copy for short name - Name file T + extension File.Copy(testFolderName, path + @"\T" + Path.GetExtension(testfile)); File.Delete(testFolderName); RunProg(testFolderName,Path.GetExtension(testfile),Path.GetFileNameWithoutExtension(testfile) ); } } catch(Exception e) { Console.WriteLine("ERROR in RUNGliChk " + e.ToString()); } Thanks
-
I copy a "ReadOnly" file. I change it's name and then go to delete it. Problem it won't delete because it is ReadOnly (At least when I remove ReadOnly it deletes fine). This is the error I receive: ERROR in test System.UnauthorizedAccessException: Access to the path "c:\test\\test.dll" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.File.Delete(String path) at Check.RunTest.DoRun(String path) in c:\project\runtest.cs:line 38 Here is my code: try { string[] testfiles = Directory.GetFiles(path); foreach( string testfile in testfiles) { string testFolderName = path + @"\" + Path.GetFileName(testfile); //Copy for short name - Name file T + extension File.Copy(testFolderName, path + @"\T" + Path.GetExtension(testfile)); File.Delete(testFolderName); RunProg(testFolderName,Path.GetExtension(testfile),Path.GetFileNameWithoutExtension(testfile) ); } } catch(Exception e) { Console.WriteLine("ERROR in RUNGliChk " + e.ToString()); } Thanks
-
Yes, you can't delete a read only file. That is not an error, it's by design. If you want to delete it, you have to change the attribute first. --- b { font-weight: normal; }
-
Can you take it one step further? I used this code to try to change the attribute: File.SetAttribute(path, FileAttributes. ); I could only find .ReadOnly and that's not what I want.