C:\_G\WWW\~ELISANET\INFO\tscmd170.html
<http://www.elisanet.fi/tsalmi/info/tscmd170.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Sat 8-Dec-2018 19:46:33

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



170} How do I get the total size of a volume, not just the available space?

  @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

Another 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

Furthermore, diskpart (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).
[Image cmd17002.gif]

One way of getting the same information in Windows XP for tallying is the following. (Also see Item #54.)
start
  Accessories
    System Tools
      System Information (or C:\WINDOWS\system32\dllcache\msinfo32.exe)
          Components
            Storage
              Drives (see Size)

[Image cmd17001.gif]

Or simply
[Image cmd17003.gif]

and e.g.
[Image cmd17004.gif]

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups thread starting 6 Jan 2009 15:45:58 +0100
  Google Groups 7 Jan 2009 21:18:40 +0000 [M]
  Google Groups May 10 2010, 5:08 am [M]
  How to use System Information (MSINFO32) command-line tool switches
  Google Groups Sun, 17 Jul 2011 09:18:37 -0400

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd170.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd170
http://www.elisanet.fi/tsalmi/info/tscmd170.html
file:///c:/_g/www/~elisanet/info/tscmd170.html