...
Syntax
Wiki Markup |
---|
*diskspace* _logical-name_\[=_path_\] \[_qty_=_nnn_\{*b*\|*k*\|*m*\|*g*\}\] \[_cond_=\{*GT*\|*LT*\}\] |
Description
...
The following example displays the amount of space available on the volume or file system that contains the directory
c:\somedir
.
Panel |
---|
Html bobswift |
<pre>
open dst=ipaddr user=uid pwd=password
diskspace dst=c:\somedir
</pre>
|
The following example verifies that the available space for the volume or file system that contains the current working directory is greater than 10GB.
Panel |
html-bobswift |
---|
<pre>
open dst=ipaddr user=uid pwd=password
diskspace dst qty=10g
if $(_lastrc.result) EQ 0
echo "At least 10 GB is available"
else
echo "Less than 10 GB is available"
end
</pre>
|
The statements below repeat the previous example using the $(_diskspace) built-in variable with the
.gb
attribute.
Panel |
html-bobswift |
---|
<pre>
open dst=ipaddr user=uid pwd=password
diskspace dst
if $(_diskspace.gb) GE 10
echo "At least 10 GB is available"
else
echo "Less than 10 GB is available"
end
</pre>
|
The following example uses diskspace in the context of a
forfiles statement, using the file's size in the comparison.
Panel |
html-bobswift |
---|
<pre>
open dst=ipaddr user=uid pwd=password
forfiles local=c:\sourcedir\afile.txt fileattrib=yes
# Make sure we have enough space available
diskspace dst=c:\targetdir qty=$(_file.size) cond=GT
# We do, copy the file.
if $(_lastrc.result) EQ 0
copy local=$(_file) dst=c:\targetdir\$(_file)
end
end
</pre>
|
The statements below repeat the previous example using the $(_diskspace) built-in variable. The
if statement only allows the file copy if the number of bytes available on
c:
is greater than the size of the input file.
Panel |
html-bobswift |
---|
<pre>
open dst=ipaddr user=uid pwd=password
forfiles local=c:\sourcedir\afile.txt fileattrib=yes
# Make sure we have enough space available
diskspace dst=c:\targetdir
# We do, copy the file.
if $(_diskspace) GT $(_file.size)
copy local=$(_file) dst=c:\targetdir\$(_file)
end
end
</pre>
|
The following example uses diskspace in the context of a
forfiles loop, using the total size of several files to determine the quantity of space needed.
Panel |
html-bobswift |
---|
<pre>
set spaceNeeded=0
open dst=ipaddr user=uid pwd=password
forfiles local=/home/datadir/*.txt fileattrib=yes
set spaceNeeded=<$(spaceNeeded) + $(_file.size)>
end
# Make sure we have enough space available
diskspace dst=c:\targetdir qty=$(spaceNeeded) cond=GT
# Only execute the "forfiles" statement if we have enough space
# for all the files.
if <"$(_lastrc.message)" EQ "SUCCESS">
forfiles local=c:\sourcedir\*.txt
copy local=$(file) dst=c:\targetdir\$(_file)
end
end
</pre>
|
The statements below repeat the previous example using the $(_diskspace) built-in variable.
Panel |
html-bobswift |
---|
<pre>
set spaceNeeded=0
open dst=ipaddr user=uid pwd=password
forfiles local=/home/datadir/*.txt fileattrib=yes
set spaceNeeded=<$(spaceNeeded) + $(_file.size)>
end
# Make sure we have enough space available
diskspace dst=c:\targetdir
# Only execute the "forfiles" statement if we have enough space
# for all the files.
if $(_diskspace) GT $(spaceNeeded)
forfiles local=c:\sourcedir\*.txt
copy local=$(file) dst=c:\targetdir\$(_file)
end
end
</pre>
|
The following example would prevent a copy if the available space for the volume or file system that contains the specified directory is less than 20MB.
Panel |
html-bobswift |
---|
<pre>
open dst=ipaddr user=uid pwd=password
diskspace dst=c:\targetdir qty=20m cond=lt
if $(_lastrc.result) EQ 0
echo "Not enough space. Will not copy."
else
echo "OK to copy"
copy local=c:\sourcedir\somefile.txt dst=c:\targetdir\somefile.txt
end
The statements below repeat the previous example using the $(_diskspace) built-in variable with the {{.mb}} attribute.
open dst=ipaddr user=uid pwd=password
diskspace dst=c:\targetdir
if $(_diskspace.mb) LT 20
echo "Not enough space. Will not copy."
else
echo "OK to copy"
copy local=c:\sourcedir\somefile.txt dst=c:\targetdir\somefile.txt
end
</pre>
|