Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6573911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:11:34+00:00 2026-05-25T15:11:34+00:00

Let say, a file has the following attributes: ReadOnly, Hidden, Archived, System . How

  • 0

Let say, a file has the following attributes: ReadOnly, Hidden, Archived, System.
How can I remove only one Attribute? (for example ReadOnly)

If I use the following, it removes all the attributes:

IO.File.SetAttributes("File.txt",IO.FileAttributes.Normal)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:11:35+00:00Added an answer on May 25, 2026 at 3:11 pm

    From MSDN: You can remove any attribute like this

    (but @sll’s answer for just ReadOnly is better for just that attribute)

    using System;
    using System.IO;
    using System.Text;
    class Test 
    {
        public static void Main() 
        {
            string path = @"c:\temp\MyTest.txt";
    
            // Create the file if it exists.
            if (!File.Exists(path)) 
            {
                File.Create(path);
            }
    
            FileAttributes attributes = File.GetAttributes(path);
    
            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                // Make the file RW
                attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
                File.SetAttributes(path, attributes);
                Console.WriteLine("The {0} file is no longer RO.", path);
            } 
            else 
            {
                // Make the file RO
                File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
                Console.WriteLine("The {0} file is now RO.", path);
            }
        }
    
        private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
        {
            return attributes & ~attributesToRemove;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say there is a file called myfile.txt with the following contents: one two
For example, let's say I have a Maven build file that has dependencies located
Let's say you have a text file like this one: http://www.gutenberg.org/files/17921/17921-8.txt Does anyone has
Let's say I have the following line in .emacs file. (setq-default default-directory ~/Desktop/mag) How
I can't come up with a solution to the following problem. Let's say i
Let's say I have the following XML file <a id=123> <b type=foo value=1 />
Let's say I have an input text file of the following format: Section1 Heading
Let's say I have a file containing the following: set_t lorem = 168 set_t
I have a file, let's say file.txt I have done git mv file.txt to
I have a properties file, let say my-file.properties. In addition to that, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.