Since Apache Ant 1.6.


Changes the attributes of a file or all files inside specified directories. Right now it has effect only under Windows. Each of the 4 possible permissions has its own attribute, matching the arguments for the attrib command.

FileSets, DirSets or FileLists can be specified using nested <fileset>, <dirset> and <filelist> elements.

Starting with Ant 1.7, this task supports arbitrary Resource Collections as nested elements.

By default this task won't do anything unless it detects it is running on a Windows system. If you know for sure that you have a "attrib" executable on your PATH that is command line compatible with the Windows command, you can use the task's os attribute and set its value to your current os.


Attribute Description Required
file the file or directory of which the permissions must be changed. Yes or nested <fileset/list> elements.
readonly the readonly permission. at least one of the four.
archive the archive permission.
system the system permission.
hidden the hidden permission.
type One of file, dir or both. If set to file, only the permissions of plain files are going to be changed. If set to dir, only the directories are considered.
Note: The type attribute does not apply to nested dirsets - dirsets always implicitly assume type to be dir.
No, default is file
verbose Whether to print a summary after execution or not. Defaults to false. No
os list of Operating Systems on which the command may be executed. No
osfamily OS family as used in the <os> condition. No - defaults to "windows"


<attrib file="${dist}/run.bat" readonly="true" hidden="true"/>

makes the "run.bat" file read-only and hidden.

<attrib readonly="false">
  <fileset dir="${meta.inf}" includes="**/*.xml"/>

makes all ".xml" files below ${meta.inf} readable.

<attrib readonly="true" archive="true">
  <fileset dir="shared/sources1">
    <exclude name="**/trial/**"/>
  <fileset refid="other.shared.sources"/>

makes all files below shared/sources1 (except those below any directory named trial) read-only and archived. In addition all files belonging to a FileSet with id other.shared.sources get the same attributes.