Saved Bookmarks
| 1. |
Solve : Checking disk space on a remote drive from a batch file? |
|
Answer» HELLO, I am running Windows XP 5.1 SP2, and do daily backups to a networked machine using a scheduled batch file. I need to do a disk space check, but I don't have Freedisk. I have downloaded several versions but none of them worked. Instead, I would like to use dir |FIND "bytes free">tempfile and then parse the output to check space but I can't get the contents of tempfile into %x batch file parameters. Please can you suggest some way of doing a disk space check from a batch file? Thanks limebear Code: [SELECT]for /f "tokens=3" %%x in ('dir <path> ^| find /i "bytes free"') do echo %%x The value of the free space is in the %%x variable and there is no need for a tempfile. Keep in mind that the value is an edited string and not numeric. Replace with a valid value. Thank you for that, I have that working. But I am still stuck. for /f "tokens=3" %%x in ('dir ^| find /i "bytes free"') call parse.bat gets me one instance of parse.bat with an indeterminate number of %1 %2 %3 etc filled with portions of the free size. But I can't see a way to get these into a single integer. Can it be done with SET and then tested with IF > ? Thanks very much limebear Sorry I should have said at the outset that I'm trying to AUTOMATE a warning when disk space gets below a threshold, so printing out a string indicating the actual space won't do it. I need some kind of test. Thanks limebearQuote Can it be done with SET and then tested with IF > YES, but it gets very strange accessing the variable. Code: [Select]setlocal enabledelayedexpansion for /f "tokens=3" %%x in ('<path> ^| find /i "bytes free"') do ( set size=%%x set size=!size:,=! echo !size! ) echo %size% By replacing the commas with nulls you should be able to do compare operations. Just note that within the for loop you access the size variable with !size!, and from outside the for loop you access the size variable as %size%. I'll leave the rest to your imagination. Thank you very much, it's all working now. cheers limebear |
|