我们是否可以通过Ant Script知道任何驱动器的空闲空间,因为我在我的部署Ant脚本中复制一个300mb大小的文件夹,所以我想在复制之前确认该驱动器中有超过300mb的空间。
查看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>
我使用了以下方法:
<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" />
脚本将失败,如果驱动器小于10gb