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#
helpquestion
3 Posts 3 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.
  • J Offline
    J Offline
    Jonathan Slenders
    wrote on last edited by
    #1

    How can i change the fileattributes of a file (or folder). I will change the Read-only, Hidden, archive,... tags but i can't find it somewhere. It was no problem to change the creation, last access and last written time, but that class (FileInfo and DirectoryInfo) doesn't have anything to change the attributes of it. Can you help me? Jonathan Slenders

    M H 2 Replies Last reply
    0
    • J Jonathan Slenders

      How can i change the fileattributes of a file (or folder). I will change the Read-only, Hidden, archive,... tags but i can't find it somewhere. It was no problem to change the creation, last access and last written time, but that class (FileInfo and DirectoryInfo) doesn't have anything to change the attributes of it. Can you help me? Jonathan Slenders

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi Jonathan. Try the System.IO.File.SetAttributes()[^] static method.

      1 Reply Last reply
      0
      • J Jonathan Slenders

        How can i change the fileattributes of a file (or folder). I will change the Read-only, Hidden, archive,... tags but i can't find it somewhere. It was no problem to change the creation, last access and last written time, but that class (FileInfo and DirectoryInfo) doesn't have anything to change the attributes of it. Can you help me? Jonathan Slenders

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        See FileInfo.Attributes (inherited form FileSystemInfo). You can use bitwise operators to change the flags. For instance, to exclude the read-only, hidden, and archive flags, you could do something like this:

        FileInfo info = new FileInfo("path");
        info.Attributes &= ~(FileAttributes.ReadOnly | FileAttributes.Hidden
        | FileAttributes.Archive);

        Microsoft MVP, Visual C# My Articles

        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