Search code examples
ant

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 space in that drive.


Solution

  • 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>