ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <>
Subject Re: chmod on windows
Date Tue, 04 Jun 2002 12:26:25 GMT
Here is how I did set the read-only flag that worked on both Unix and
Windows.  Not pretty, but it works.  (and even shows off the
ReadOnlySelector I created!)

<?xml version="1.0" ?>
<project name="selectors" default="main">

  <property name="build.dir" location="build"/>
  <property name="temp.dir" location="${build.dir}/temp"/>
  <property name="src.dir" location="src"/>
  <property name="data.dir" location="data"/>

  <target name="init">
    <mkdir dir="${build.dir}"/>

    <condition property="">
      <os family="windows"/>

  <target name="clean">
    <delete dir="${build.dir}"/>

  <target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${build.dir}"/>

  <target name="setup-test-init">
    <delete dir="${temp.dir}"/>
    <mkdir dir="${temp.dir}"/>

    <delete dir="${data.dir}"/>
    <mkdir dir="${data.dir}"/>

    <echo file="${data.dir}/writable.dat">writable</echo>
    <echo file="${data.dir}/nonwritable.dat">nonwritable</echo>

  <target name="setup-test-windows" if="">
    <exec executable="cmd.exe">
      <arg line="/c attrib +R"/>
      <arg file="${data.dir}/nonwritable.dat"/>
    <exec executable="cmd.exe">
      <arg line="/c attrib -R"/>
      <arg file="${data.dir}/writable.dat"/>

  <target name="setup-test" depends="setup-test-init,setup-test-windows">
    <chmod file="${data.dir}/nonwritable.dat" perm="u-r"/>
    <chmod file="${data.dir}/writable.dat" perm="u+r"/>

  <target name="test" depends="compile,setup-test">

    <selector id="selector">
      <custom classname="org.example.antbook.ReadOnlySelector"

    <copy todir="${temp.dir}">
      <fileset dir="${data.dir}">
        <selector refid="selector"/>

    <available file="${temp.dir}/writable.dat" property="test.failed"/>
    <fail if="test.failed">Failed!  Writable file copied!</fail>
    <echo>Test passed</echo>

  <target name="main" depends="test"/>


----- Original Message -----
From: "Rum Pel" <>
To: "Sebastien Diot" <>
Cc: "Ant Users List" <>
Sent: Tuesday, June 04, 2002 6:01 AM
Subject: Re: chmod on windows

> -----
> > I meant that you can change read-only (and maybe some other) attributes
> > with "attrib", but that you can't change the "executable" attribute,
> > because it just doesn't exists under Windows.
> >
> You are right, and I am not bothered about the executable attribute but
> the "read attribute" which windows supports.
> I just want to make a file read-only(and vice-versa), is there a platform
> independant
> way to do this?
> --rp
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message