Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. FileAttributes

FileAttributes

Scheduled Pinned Locked Moved C#
help
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SJR_1
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • S SJR_1

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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; }

      S 1 Reply Last reply
      0
      • G Guffa

        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; }

        S Offline
        S Offline
        SJR_1
        wrote on last edited by
        #3

        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.

        G 1 Reply Last reply
        0
        • S SJR_1

          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.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Use FileAttributes.Normal. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups