You are not logged in.
Pages: 1
Hi can some one tell me how to check the disk space in MB from a command line / bat file ?
i also want to get those details from one server to another serevr , please let me know thanks!
Offline
For your first problem, try this;
@echo off
setlocal enabledelayedexpansion
echo DL Free MB
echo -- -------
for /F "tokens=1,*" %%A in ('fsutil fsinfo drives') do @for %%K in (%%B) do @for %%U in (%%K) do @for /F "tokens=1 delims=\" %%e in ('fsutil fsinfo drivetype %%U ^| find "Fixed"') do @for /F "tokens=4" %%o in ('fsutil fsinfo ntfsinfo %%e ^| find "Free Clusters"') do @set /a free=%%o / 256 > nul & echo %%e !free!Note Assumes fixed drives are formatted NTFS with 4096 Byte cluster size.
Offline
Doesn't work correctly on my WinXP -- only shows the first drive it finds.
I believe it'll be because the output of "fsutil fsinfo drives" is slightly different than on, say, Vista.
Offline
Having problem with the video card in my XP machine, so didn't check the script on that platform. Sorry about that.
Here is my 'fsutil fsinfo drives' output on my Win 7 machine;
Drives: C:\ D:\ F:\Is it the backslashes?
Last edited by Drewfus (2010-02-09 07:05:55)
Offline
For your first problem, try this;
@echo off setlocal enabledelayedexpansion echo DL Free MB echo -- ------- for /F "tokens=1,*" %%A in ('fsutil fsinfo drives') do @for %%K in (%%B) do @for %%U in (%%K) do @for /F "tokens=1 delims=\" %%e in ('fsutil fsinfo drivetype %%U ^| find "Fixed"') do @for /F "tokens=4" %%o in ('fsutil fsinfo ntfsinfo %%e ^| find "Free Clusters"') do @set /a free=%%o / 256 > nul & echo %%e !free!Note Assumes fixed drives are formatted NTFS with 4096 Byte cluster size.
maybe this:
@Echo oFF
Setlocal EnableDelayedExpansion
Echo Drive FreeSpace MB
Echo ----- ------------
Set List=&For /F "tokens=*" %%A in ('fsutil fsinfo drives^|MORE') do Set "List=!List! %%A"
For %%B In (%List:*:=%) Do For /F "Delims=-\" %%C In ('fsutil fsinfo drivetype %%B ^| Find /i "Fixe"') Do (
For /F "Tokens=2 Delims=:" %%D In ('Fsutil Fsinfo NTFSInfo %%C ^|Findstr /I "free libre"') Do (
Set /A Free=0
Set /A "Free=%%D/256"
Echo, %%C !Free! MB
)
)
Goto:EOFOffline
Having problem with the video card in my XP machine, so didn't check the script on that platform. Sorry about that.
Here is my 'fsutil fsinfo drives' output on my Win 7 machine;
Drives: C:\ D:\ F:\Is it the backslashes?
No, it was discussed at length here: http://ss64.org/viewtopic.php?id=327
I propose the following (I believe it'll work on XP, Vista and 7):
for /F "tokens=*" %%A in ('fsutil fsinfo drives ^| find /v ""') do (
@for %%K in (%%A) do if "%%K" NEQ "Drives:" (
@for %%U in (%%K) do (
@for /F "tokens=1 delims=\" %%e in ('fsutil fsinfo drivetype %%U ^| find "Fixed"') do (
@for /F "tokens=4" %%o in ('fsutil fsinfo ntfsinfo %%e ^| find "Free Clusters"') do (
@set /a free=%%o / 256 > nul & echo %%e !free!
)
)
)
)
)I've broken it down from the single line version to make it easier to understand for the uninitiated.
Functional amendments (rather than the clarity changes) are highlighted in red here:
for /F "tokens=*" %%A in ('fsutil fsinfo drives ^| find /v ""') do (
@for %%K in (%%A) do if "%%K" NEQ "Drives:" (
Offline
Odd the origanal one by Drewfus gives me this on win 7 Home premium
DL Free MB
-- -------
C: 13291
D: 2590
E: 74
F: 2922
I: 9905
X: 247859
Y: 283415
Z: 235874
But the last one from Bluesxman gives
C: !free!
D: !free!
E: !free!
F: !free!
I: !free!
X: !free!
Y: !free!
Z: !free!
Last edited by Chimaera (2010-02-10 12:17:33)
Offline
But the last one from Bluesxman gives
C: !free!
D: !free!
E: !free!
F: !free!
I: !free!
X: !free!
Y: !free!
Z: !free!
That'll be because you've used the command I provided in isolation, whereas it was intended as a modification to the original script -- which has delayed expansion enabled.
Last edited by bluesxman (2010-02-10 11:35:29)
Offline
aah my bad lol
Offline
Pages: 1