----^--->
/\

//\\
//The\
/Sy
stem\
////
Guard
\

In the mount of the LORD it shall be seen. Genesis 22:14

GetFreeM

Booming Or Fuming? | MasterCatalog | ntlib (FREE) | NTCmdLib | MtCmds | Scripts | Almost Free | TheGuardBook | Help

 

Types of
.Mount/\Commands

.CrystalClear | .ExactName | .ExitELn | .GetValue | .ifCondition | .ifELn | .IsPattern | .ListValue | .NetValue | .NowValue | .RedirRapids | .ReliableReporting | .RestoreValue | .SetELn | .ValueEcho

.GetValue
Series

  .GetCD | .GetDate | GetDirSize | GetDirSizeM | GetFree | GetFreeM | GetIPAddr | GetIPGateway | GetIPMask | GetLogDate | GetLogTime | GetLogTimeP | GetMac | GetNic | GetOS | GetRole | GetTempFile | GetTime | GetTimeP

.GetFreeM

Description

  1. Displays the available free space (in Millions of bytes) on the current drive
  2. Saves the value in #FreeM
  3. Saves the previous value of #FreeM (if it exists) in #Previous_#FreeM
  4. Sets errorlevel based on the result
     
Using this offset, we can easily perform mathematical calculations on values up to 1.776 Petabytes (PB), 1,818 Terabytes (TB) or 1,862,645 Gigabytes (GB), without exceeding the limits of the native shell scripting environment.

Syntax

%.GetFreeM%    

Parameters and Switches

none

   

Errorlevels and Output Variables

Display to
STDOUT

 

Value of
#Free

 

Error
Level

  Description of Result

0

 

Actual Bytes
(in Millions)

 

123

  Less than 1M bytes free

1 to 999

 

Actual Bytes
(in Millions)

 

3

  Less than 1,000M bytes free

1000
to
999999

 

Actual Bytes
(in Millions)

 

2

  Less than 1,000,000M bytes free

1000000
to
999999999

 

Actual Bytes
(in Millions)

 

1

  Less than 1,000,000,000M bytes free

1000000000
to
2000000000

 

Actual Bytes
(in Millions)

 

0

  Bytes free is between 1,000,000,000M and 1,999,999,999M

2000000000

 

Actual Bytes
(in Millions)

 

0

  Bytes free is 2,000,000,000M or greater

Examples, Notes and Instructions

Example 1 - at the command line

NT
2K
XP
K3
C:\GuardPost>%.GetFreeM%
1925
C:\GuardPost>ECHO:%Errorlevel%
2
C:\GuardPost>SET #Free
#FreeM=1925
C:\GuardPost>
D:
D:\>%.GetFreeM%
11
D:\>ECHO:%Errorlevel%
3
D:\>SET #FreeM
#Free=11
D:\>SET #Previous_#Free
#Previous_#Free=1925

Example 2 - a quick free space report - from inside a script

ReportFreeSpace.cmd

01. (((%.GetLogDate%)&(%.GetLogTime%))%.Silent%)                                    ^
02. &(
03.   FOR /F %%A IN ('%.eNetView%') DO @(
04.      FOR %%B IN (%#UPPER:~4%) DO @(
05.         %.Kity% ( (PUSHD \\%%A\%%B$)                                          ^
06.            && (%.GetFreeM% %.Silent%                                                 ^
07.               & CALL ECHO ^%%#LogDate^%%,^%%#LogTime^%%,%%A,%%B,^%%#FreeM^%%  ^
08.               & POPD
09.            )
10.         )
11.      )
12.   )
13.)

The above command provides a date and time coded Free Space Report for all local drives on all machines that display in the output of "Net View". It is assumed that you have access to the administrative shares (C$, D$, etc.).

The command interpreter processes this as one line of code, so it's usually quite fast. In extremely large networks, the code is easily modified to use a temporary file for storing the machine names.

*******

The output of this command is a comma separated list that looks like this:

20040416,052826,SERVER1,C,1067
20040416,052826,SERVER1,D,3754
20040416,052826,WORKSTATION1,C,801
20040416,052826,WORKSTATION1,D,1234
20040416,052826,WORKSTATION1,L,5468
20040416,052826,WORKSTATION1,R,0
.
.
.
etc.



The output format is YYYYMMDD,HHMNSS,Computername,Drive,FreeSpaceInMillionsOfBytes


How does this work?

  1. .GetLogDate and .GetLogTime retrieve YYYYMMDD and HHMNSS and save these values in variables named #LogDate and #LogTime. The .Silent command suppresses the display of YYYYMMDD and HHMNSS to the console.
  2. The outer loop (FOR /F %A) sends the output of the command .eNetView (a formatted list of all systems displayed by the "Net View" command) to the inner loop (FOR /F %B). The inner loop processes a space-delimited list of drive letters from C through Z and tries to execute a PUSHD command to the administrative share associated with that drive letter on each system (\\ComputerName\C$, \\ComputerName\D$, etc.)
  3. The .Kity command (KITY stands for Keep-It-To-Yourself) suppresses any errors from PUSHD when it does not find, or cannot access, any of the administrative shares.
  4. If PUSHD is successful, commands after the "&&" are executed for the machine represented by %A and the drive letter represented by %B.
  5. The command .GetFreeM retrieves the free space, in whole millions of bytes, that is available on the subject drive and saves this value in variable #FreeM. Again, we use %.Silent% to suppress the console display of the free space value.
  6. The CALL ECHO command displays the final output while dynamically expanding the contents of #LogDate, #LogTime and #FreeM.
  7. Finally POPD returns us to the original directory (only if PUSHD was successful).

  • All output is in whole Millions of bytes (1,000,000) NOT Megabytes (1,048,576)
  • Output is displayed to STDOUT
  • To suppress console display, use

    %.GetFreeM% %.Quiet%

{errorlevel and output variable(s) will still be available}


.GetValue
Series

  .GetCD | .GetDate | GetDirSize | GetDirSizeM | GetFree | GetFreeM | GetIPAddr | GetIPGateway | GetIPMask | GetLogDate | GetLogTime | GetLogTimeP | GetMac | GetNic | GetOS | GetRole | GetTempFile | GetTime | GetTimeP

Related .Mount/\Commands, #Constants, $Functions, :Procedures

Resource

  Short Description
#Free   Free space on current drive - values of 2,000,000,000 or greater will be displayed as 2000000000
#Free_d   Free space on Drive d (in bytes, where d is any accessible local or remote drive)
#FreeM_d   Free space on Drive d (in Millions of bytes, where d is any accessible local or remote drive)

 

K

E

Y

Common Commands INTERNAL External /SWITCH Parameter Help text AddonTool
Mounted Commands .Mount/\Command CmdShorthand #Constant $FUNCTION :Procedure !GuardNote
Operating Systems NT/2K/XP/K3 NT Only NT/2K 2K Only 2K/XP XP Only XP/K3 K3 Only 2K/XP/K3
/\
//\\
//
The\
/Sy
stem\
////
Guard
\
COME ON UP WITH US!
and
Congratulations On Your Decision
to
RISE ABOVE
THE REST!

^
/
!\
/LIB\

TheSystemGuard.com [Revised: 2007-03-29]
Copyright © 1995-2007, JWC
Computer Communications,
All Rights Reserved, Worldwide.
 Disclaimer       Privacy       About Us       More


Communication Is Business!

We Master It With Knowledge!

^
/
.\
/M^C\