Set file attribute

In this chapter you will learn:

  1. How to change file attribute

Change file attribute

using System;//from   ja va2  s.  c  o m
using System.IO;

class Class1
{
  [STAThread]
  static void Main(string[] args)
  {
           if( args[1] == "+r" )
           {
               File.SetAttributes( args[0], File.GetAttributes(args[0]) | FileAttributes.ReadOnly );
           }
           else if( args[1] == "-r" )
           {
               File.SetAttributes( args[0], File.GetAttributes(args[0]) & (~FileAttributes.ReadOnly) );
           }
  }
}

Next chapter...

What you will learn in the next chapter:

  1. How to change file time
  2. Set file last write time
Home » C# Tutorial » File, Path
File creation
Deleting Files
Put to recycle bin
File Exists
File moving
File size
File attribute
Set file attribute
File time change
File time
Random file name
Temporary file
Path
Directory creation
Delete directory
Path existance
Change the path
Current Path
Directory listing
Recursive Path Listing
Combine path
Calculate Directory Size
Invalid path characters
System path
Directory copy
Drive
Drive information
File access rule
File System watcher