Saturday, January 10, 2009

Change attributes of a file using the command prompt

The attrib command is used to Display, set, or remove attributes assigned to files or directories. using attrib without parameters displays attributes of all files in the current directory.
Syntax
attrib [{+|-}r] [{+|-}a] [{+|-}s] [{+|-}h] [{+|-}i] [drive:][path][fileName] [/s [/d] [/l]]
+ is for setting the attribute
- is for clearing an attribute
r is for
the Read-only file attribute.
a is for the Archive file attribute.
s is for the System file attribute.
h is for the Hidden file attribute.
i is for the Not Content Indexed file attribute.
/s Applies attrib and any command-line options to matching files in the current directory and all of its subdirectories.

/d Applies attrib and any command-line options to directories.

/l Applies attrib and any command-line options to the Symbolic Link, rather than the target of the Symbolic Link.

If a file has the System (s) or Hidden (h) attribute set, you must clear the attribute before you can change any other attributes for that file.

Examples:
To assign the Read-only attribute to the file named Report.txt, type:
attrib +r report.txt
To remove the Read-only attribute from files in the Public directory and its subdirectories on a disk in drive B, type:
attrib -r b:\public\*.* /s

No comments:

Post a Comment