EPM Automate - DOS Commands for Checking Available Disk Space
I recently answered this question on Oracle Cloud Customer Connect [you are signed up for CCC, yes?] and wanted to share the answer here.
A user is setting up EPM Automate to do snapshot downloads. There is a need to check the available disk space and then delete prior backups as necessary. The question was how do you check available disk space. Here are the steps.
The easiest way to find the available disk space is with the DIR command. The output can look something like this.
The output starts with the word Volume and can go for any number of lines based on the contents. The number to capture is 25,998,811,136, but without the separators and as a variable so that a comparison can be made.
First, use the DIR command with a redirect to write the output above to a file. Use the /-C parameter to remove the separators.
DIR /-C > file.txt
The output of this will look like above but without the separators. Next, isolate the bytes free line vs all of the others with a FIND command. Search for bytes free. Redirect to another file.
FIND "bytes free" file.txt > line.txt
The output of this will look like the last line above. Next, use the FOR command to find the right part of the line. The parameters allow specifying a delimiter, but if nothing is specified then a space will be used as a delimiter. Note, if the below command is used in a batch file, use %%I as shown. If typing this in manually to a command window, use %I instead.
FOR /F "TOKENS=3" %%I IN (LINE.TXT) DO (SET FREESPACE=%%I)
So now we have a variable with a number in it. Is this useful? Maybe, maybe not. The next step would be to subtract a predetermined target amount from the available space to see if the available space is above or below the target. The SET command with the /A parameter will do this. But, it is limited to 32-bit numbers, meaning it doesn't work for numbers larger than 2,147,483,647.
So, a little more work needs to be done. Assuming the target is 10GB (10,000,000,000) we can reduce everything to GB instead of working with the full number. Use the SET command to pull out just the wanted part of the number (GBs only) into a new variable.
SET FREESPACEGB=%FREESPACE:~0,-9%
Now all that is left is a variable with just the GB value: in this case, 25. Then it would be an easy comparison to compare to our 10GB target. In the case that available disk space is under 1GB, then the above truncation may cause an issue. Doing the comparison in MB instead would get around that. Change the -9 above to -6 and then compare the output to 10000 instead of 10.