how can i know the drive free space through Ant script
Is it possible that we can know the free space of any drive through Ant Script, because I am copying one folder of 300mb size in my deployment ant script so I want to confirm before copy that there is more than 300mb 开发者_Python百科space in that drive.
Look at hasfreespace: http://ant.apache.org/manual/Tasks/conditions.html
<?xml version="1.0"?>
<project name="test" default="test" basedir=".">
<target name="test" depends="exists,not-exists">
<echo message="Test target"/>
</target>
<target name="exists" if="space-exists">
<echo message="Space exists"/>
</target>
<target name="not-exists" unless="space-exists">
<echo message="Space does not exist"/>
</target>
<condition property="space-exists">
<!-- Change this to 10000G to see it failing -->
<hasfreespace partition="/" needed="1M"/>
</condition>
</project>
I used following approach.
<echo message="Checking free space on drive D:" />
<fail message="Drive D: has less than 10 Gb" >
<condition>
<not>
<hasfreespace partition="d:" needed="10G"/>
</not>
</condition>
</fail>
<echo message="Drive D: has 10 Gb or more" />
Script will fail, if drive has less, than 10 GB.
精彩评论