@echo off & setlocal enableextensions
::
:: Which drive? Define in here or as a parameter to the script
set drive_=C:
if not "%~1"=="" set drive_=%~1
::
:: Build a Visual Basic Script
set skip=
set temp_=%temp%
if defined mytemp if exist "%mytemp%\" set temp_=%mytemp%
set vbs_=%temp_%\tmp$$$.vbs
>"%vbs_%" findstr "'%skip%VBS" "%~f0"
::
:: Run the script with Microsoft Windows Script Host Version 5.6
for /f "tokens=1-3 delims= " %%a in (
'cscript //nologo "%vbs_%" "%drive_%"') do (
set totalSizeBytes_=%%a
set totalSizeMB_=%%b
set totalSizeGB_=%%c)
If "%totalSizeBytes_%"=="NotReady" (echo %drive_% not ready&goto :_out)
If "%totalSizeBytes_%"=="NotFound" (echo %drive_% not found&goto :_out)
echo %drive_% %totalSizeBytes_% bytes
echo %drive_% %totalSizeMB_% MB
echo %drive_% %totalSizeGB_% GB
::
:: Clean up
:_out
for %%f in ("%vbs_%") do if exist %%f del %%f
endlocal & goto :EOF
'
'The Visual Basic Script
Set arg = WScript.Arguments 'VBS
Set fso = CreateObject("Scripting.FileSystemObject") 'VBS
If fso.DriveExists(arg(0)) Then 'VBS
Set d = fso.GetDrive(fso.GetDriveName(arg(0))) 'VBS
If d.IsReady Then 'VBS
s = d.TotalSize 'VBS
s = s & " " & Int(d.TotalSize/1024/1024) 'VBS
s = s & " " & Round(d.TotalSize/1024/1024/1024,2) 'VBS
WScript.Echo s 'VBS
Else 'VBS
WScript.Echo "NotReady" 'VBS
End If 'VBS
Else 'VBS
WScript.Echo "NotFound" 'VBS
End If 'VBS
The output could be e.g.
C:\_D\TEST>cmdfaq
C: 250056704000 bytes
C: 238472 MB
C: 232.88 GB
or
C:\_D\TEST>cmdfaq E:
E: not ready
or
C:\_D\TEST>cmdfaq F:
F: not found
method, but it requires a local NTFS
volume and the FSUTIL utility requires that you have administrative
privileges. (As an unrelated aside notice the trick of dividing a FOR
command on several lines.)
@echo off & setlocal enableextensions
set drive_=C:
if not "%~1"=="" set drive_=%~1
::
for /f "tokens=2 delims=:" %%a in (
'fsutil volume diskfree %drive_%^|
findstr /i /c:"Total # of bytes"') do (
set totalSizeBytes_=%%a)
if defined totalSizeBytes_ echo %drive_% %totalSizeBytes_% bytes
if not defined totalSizeBytes_ echo %drive_% The size could not be resolved
endlocal & goto :EOF
The output could be e.g.
C:\_D\TEST>cmdfaq
C: 250056704000 bytes
(requiring
administrative privileges) can be used to see the volume information.
Since the volume labels could be missing and/or the types could vary
from user to user, only the entire information is given below. The
rest is left up to the user (see the discussion on the second
reference).
One way of getting the same information in Windows XP for tallying is
the following. (Also see
and e.g.