How to convert bytes to GB vbscript??

Hi I need to find the total size of my C: partition and how much free space it contains. For that I have written a vbscript which works fine but it shows the value of total size and free space in bytes. I need to show it in GB. How it can be done any help??
Below is my script,
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems
    If objItem.Name = "C:" then
        Wscript.Echo "FreeSpace: " & objItem.FreeSpace
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "Size: " & objItem.Size
    End If
Next

Hi
You can query properties of the drive object (file system object) to enumerate the total, used and available space in bytes then convert the values to gigabytes. See the code below
Cheers Matt :)
Option Explicit
Dim objFSO, scriptBaseName
Dim drive, driveLetter, totalSize, freeSpace, usedSpace
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
scriptBaseName = objFSO.GetBaseName(Wscript.ScriptFullName)
driveLetter = "C:\"
Set drive = objFSO.GetDrive(driveLetter)
totalSize = drive.TotalSize
freeSpace = drive.FreeSpace
usedSpace = totalSize - freeSpace
If Err.Number <> 0 Then
WScript.Quit
End If
MsgBox driveLetter & " drive is " & FormatGB(totalSize) & " GB" & vbCrLf & _
driveLetter & " drive is using " & FormatGB(usedSpace) & " GB" & vbCrLf & _
driveLetter & " drive has " & FormatGB(freeSpace) & " GB available", vbInformation, scriptBaseName
On Error Goto 0
'Name : FormatGB -> Format Bytes to GigaBytes.
'Parameters : size -> Numeric value in Bytes.
'Return : FormatGB -> Numeric value in GigaBytes to two decimal places.
Function FormatGB(size)
FormatGB = FormatNumber(size / (1024 * 1024 * 1024), 2,0,0,0)
End Function

Similar Messages

  • How to convert bytes[] into File object

    hi
    how to convert byte array into File object
    pls.. help me
    Regards
    srinu

    rrrr007 wrote:
    Hi,
    How to convert bytes[] into multipage File object?? ]There's no such thing as a "multipage File object." You ought to re-read this thread closely, and read the [API docs for File|http://java.sun.com/javase/6/docs/api/java/io/File.html] to clear up your confusion about what a File object is.
    I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream. Then you need a pdf API, like iText or fop. You can't just concatenate pdf files, word docs, excel sheets, etc., like you can text files. Google for java pdf api.

  • How to convert byte into string

    can any tell me how to convert byte into string
    when im an debugging thid code in eclipse it shows the result in integer format instead of string but in command prompt it is showing result in string format..........plz help
    package str;
    import java.io.*;
    public class Testfile {
    public static void main(String rags[])
    byte b[]=new byte[100];
    try{
    FileInputStream file=new FileInputStream("abc.txt");
    file.read(b,0,50);
    catch(Exception e)
         System.out.println("Exception is:"+e);
    System.out.println(b);
    String str=new String(b);
    System.out.println(str);
    }

    Namrata.Kakkar wrote:
    errors: count cannot be resolved and Unhandled exception type Unsupported Encoding Exception.
    If i write an integer value instead of "count" then Unhandled exception type Unsupported Encoding Exception error is left.This is elementary. You need to go back to [http://java.sun.com/docs/books/tutorial/|http://java.sun.com/docs/books/tutorial/] .

  • How to convert bytes[] into multipage File object

    Hi,
    How to convert bytes[] into multipage File object??
    I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream.
    Thanks for you help in advance..

    Only text format allows you to concatenate two files together to get a longer files.
    Most formats have a header and a footer and so you cannot simply add one to the other.
    You need to use a PDF API which will allow you to build the new document (if one exists)

  • How to convert bytes to GB inside of a text file

    I'm using a PS script to automate WSUS cleanup and then output the results to a text file which is then emailed to me.
    The output for Diskspace Freed is displayed in bytes, I would like to convert this to GB, but I am having trouble getting this to work.
    Here is what I was attempting to work with, but it is not working properly (the 2nd line). 
    Get-WsusServer | Invoke-WsusServerCleanup -CleanupObsoleteUpdates -CleanupUnneededContentFiles | Out-File "C:\Users\USER1\Downloads\WSUS Cleanup Log\cleanup $(get-date -f MM-dd-yy).txt"
    #(Get-Content "C:\Users\USER1\Downloads\WSUS Cleanup Log\cleanup $(get-date -f MM-dd-yy).txt") | ForEach-Object {$_."diskspace free" / 1MB} | Set-Content "C:\Users\USER1\Downloads\WSUS Cleanup Log\cleanup $(get-date -f MM-dd-yy).txt""C:\WSUS PS Script\cleanup $(get-date -f MM-dd-yy).txt"
    Send-MailMessage -to [email protected] -Subject "WSUS Cleanup" -Attachments "C:\Users\USER1\Downloads\WSUS Cleanup Log\cleanup $(get-date -f MM-dd-yy).txt" -SmtpServer 192.X.X.X -from [email protected]

    Hi Granite,
    I've got to guess here - don't have a handy 2012R2 Wsus Server at hand and I'm extrapolating from the Technet Library's documentation example output for Invoke-WsusServerCleanup - but this is what I came up with:
    $File = "C:\Users\USER1\Downloads\WSUS Cleanup Log\cleanup $(get-date -f MM-dd-yy).txt"
    $Script = {
    if ($_ -match "diskspace free")
    $Bytes = ($_.Trim().Split(":") | Select -Last 1).Trim()
    $String = ($_.Trim().Split(":") | Select -First 1).Trim() + ": "
    $String += "{0:n3}" -f ($Bytes / 1GB)
    $String += "GB"
    $String
    else { $_ }
    Get-WsusServer | Invoke-WsusServerCleanup -CleanupObsoleteUpdates -CleanupUnneededContentFiles | ForEach-Object $script | Out-File $File
    Send-MailMessage -to [email protected] -Subject "WSUS Cleanup" -Attachments $File -SmtpServer 192.X.X.X -from [email protected]
    If this doesn't work out for you, please post the actual output of the Cleanup Command.
    Cheers,
    Fred
    There's no place like 127.0.0.1
    Thanks for the response, this is exactly what I was looking for!
    The script ran with no errors. The output does show as GB, however since the script was already ran today there value is currently 0. I will test this again in a couple of days.

  • How to convert bytes to megabytes or gigabytes in graph ?

    Hello,
    looking at Logical disk Read/sec or  Network adapter Bytes received/sec graph. Data is shown in Bytes. it is very difficult to read it. How to change it to megabytes or gigabytes ?
    For example this graph is very hard to understand, but if it was in megabytes/sec it was very different: 

    You cannot custom the y-axis scale in perfromance widget. fr detail, pls. refer
    http://scomblog.wordpress.com/2013/10/30/scom2012-dashboard-limitations/
    Roger

  • How to convert character streams to byte streams?

    Hi,
    I know InputStreamReader can convert byte streams to character streams? But how to convert the character streams back to byte streams? Is there a Java class for that?
    Thanks in advance.

    When do you have to do this? There's probably another way. If you just start out using only InputStreams you shouldn't have that problem.

  • How to convert an Integer to byte[] without lose data?

    How to convert an Integer to byte[] without lose data?

    I use the following to convert any java Object to a byte array
    public static byte[] getBytes(Object obj) throws java.io.IOException
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            oos.close();
            bos.close();
            byte [] data = bos.toByteArray();
            return data;
    }

  • How to convert a Image object to byte Array?

    Who can tell me, how to convert Image object to byte Array?
    Example:
    public byte[] convertImage(Image img) {
    byte[] b = new byte...........
    return b;

    Hello,
    any way would suit me, I just need a way to convert Image or BufferedImage to a byte[], so that I can save them. Actually I need to save both jpg and gif files without using any 3rd party classes. Please help me out.
    thanx and best wishes

  • How to convert an int number to a byte array, and how to convert back?

    Hello, everybody,
    Just as the topic, if I have an int number(which should have 32-bit, or 4-byte), how can I convert it into a byte array. And also, how to convert it back.
    Thank you in advance!

    Alternatively you can use ByteBuffers to do this work for you
    // to a Byte Array
    int originalInt =...;
    ByteBuffer myBuffer = ByteBuffer.allocate(4);
    myBuffer.putInt( originalInt );
    byte myArray[] = myBuffer.array();
    // and back to an int
    ByteBuffer myOtherBuffer = ByteBuffer.wrap(myArray);
    int finalInt = myOtherBuffer.getInt();

  • How to convert a certificate from byte[] typeback to its original type

    Doing work about transfer Certificate through network using socket, after using
    Certificate.getEncode() convert it into byte[] type, then send through network, but
    at the receiver side, don't know how to convert the byte[] format back to the
    Certificate? Or there is a better way to transfer Certificate as a file through
    socket?

    If it is an X509 one:
    Certificates are instantiated using a certificate factory. The following is an example of how to instantiate an X.509 certificate:
    InputStream inStream = new FileInputStream("fileName-of-cert");
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream);
    inStream.close();

  • How to Convert Integer to byte[n]!Help

    I have a Integer 314,Convert to hex is 0x13a,I want to convert to byte[2],and byte[0] equals 0x13 and byte[1] equals [0x30];I use this method convert byte[4],
    int iVal = 314;
    byte [] bVals = new byte[4];for( int i=0; i<4; i++ ) { 
    bVals<i> = (byte)(iVal & 255);
    iVal >>= 8;
    Not I want to result.Please help!

    Try:
    int iVal = 0x01FF03F0;
    byte [] bVals = new byte[4];
    for(int i=3; i>=0; i--) {
        bVals[i] = (byte)(iVal & 255);
        iVal >>= 8
    //print results
    for (int i = 0; i < 4; i++) {
       int temp = bVals[i] & 0xFF;  // avoid displaying negative numbers
       System.out.println("byte " + i + " = " +  Integer.toHexString(temp));
    }

  • Convert byte array to table of int

    [http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
    I'm pretty new with PL/SQL.
    I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
    The code converts byte array to table of int.
    The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
    The TSQL code is:
    CREATE FUNCTION dbo.GetTableVarchar(@Data image)
    RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
    Value Varchar(8000))
    AS
    BEGIN
    --First Test the data is of type Varchar.
    IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
    --Loop thru the list inserting each
    -- item into the variable table.
    DECLARE @Ptr int, @Length int,
    @VarcharLength smallint, @Value Varchar(8000)
    SELECT @Length = DataLength(@Data), @Ptr = 2
    WHILE(@Ptr<@Length)
    BEGIN
    --The first 2 bytes of each item is the length of the
    --varchar, a negative number designates a null value.
    SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
    SET @Ptr = @Ptr + 2
    IF(@VarcharLength<0)
    SET @Value = NULL
    ELSE
    BEGIN
    SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
    SET @Ptr = @Ptr + @VarcharLength
    END
    INSERT INTO @DataTable (Value) VALUES(@Value)
    END
    RETURN
    END
    It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
    The C# code is:
    public byte[] Convert2Bytes(int[] list)
    if (list == null || list.Length == 0)
    return new byte[0];
    byte[] data = new byte[list.Length * 4];
    int k = 0;
    for (int i = 0; i < list.Length; i++)
    byte[] intBytes = BitConverter.GetBytes(list);
    for (int j = intBytes.Length - 1; j >= 0; j--)
    data[k++] = intBytes[j];
    return data;
    I tryied to convert the TSQL code to PL/SQL and thats what I've got:
    FUNCTION GetTableInt(p_Data blob)
    RETURN t_array --t_array is table of int
    AS
    l_Ptr number;
    l_Length number;
    l_ID number;
    l_data t_array;
    BEGIN
         l_Length := dbms_lob.getlength(p_Data);
    l_Ptr := 1;
         WHILE(l_Ptr<=l_Length)
         loop
              l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
              IF(l_ID<-2147483646)THEN
                   IF(l_ID=-2147483648)THEN
                        l_ID := NULL;
                   ELSE
                        l_Ptr := l_Ptr + 4;
                        l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
                   END IF;
                   END IF;
    l_data(l_data.count) := l_ID;
              l_Ptr := l_Ptr + 4;
         END loop;
         RETURN l_data;
    END GetTableInt;
    This isn't work.
    This is the error:
    Error report:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    06502. 00000 - "PL/SQL: numeric or value error%s"
    I think the problem is in this line:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    but I don't know how to fix that.
    Thanks,
    MTs.

    I'd found the solution.
    I need to write:
    l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
    instead of:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works.

  • How to convert BLOB into a String

    Hi,
    I got a blob column from the database.
    It contains one XML File.
    How to convert it into String.
    I need the code for how to convert the blob into String
    Thanks in Advance.

    A blob would be a byte-array, which you can use in the String(byte[]) constructor

  • How to convert hex into a string value

    hei evryone!
    can anyone please help me on how to convert a hex value into a string suppose.. Example i want to convert 4275646479 which is a hex value, into a string "BUDDY"? how will i do that???
    Any suggestion, tutorial site would be appreciated?
    Thx!

    something like this will convert string to byte[]
    e.g.
    you want to convert following.
    656667 => ABC
    String toConvert = "656667";
    byte[] returnVal = String2byteArr (toConvert );
    String FinalStr = new String(returnVal);
    public static byte[] String2byteArr(String Result)
    byte[] byteRet = new byte[Result.length()/2];
    int k=0;
    for (int j=0; j<(Result.length()); j+=2)
    try
    Integer I = new Integer (0);
    I = I.decode ("0x"+Result.substring(j, j+2));
    int i = I.intValue ();
    if (i > 127)
    i = i - 256;
    byteRet[k++] = new Integer(i).byteValue();
    catch(Exception e)
    System.err.println(e);
    return byteRet;
    }// String2byteArr
    Hope this will help you, So that i can get 3$ (:-)
    Avi

Maybe you are looking for

  • ITunes Disables My Internet On Vista 64-Bit

    I don't know if anyone has ever heard of this issue, but let me detail this as much as I can, and see if anyone knows of a work around... So I recently set up my girlfriend's network, with her ISP's modem and a Linksys wireless router (http://www.lin

  • Disappearing copy of email in the body of all main in sent box

    Almost every day, I refer to previous email I have sent that is located in the "sent" mail folder. At least once each day or two, when I click on a letter within the "sent" folder, the body of the email contains the following message" "The message fr

  • Cover flow doesn't work with Nano Firmware update 1.03

    Is anybody facing this problem... the cover flow pictures don't show up now.. with firmware 1.03. Even if I re-ad the CD cover images to the songs... somehow or rather it doesn't show up with this firm ware... Any help?

  • Hyperion add-ins in Excel

    hi, after added the hyperion add-ins (for installing smartview), my user has difficulting working on her normal excel file which is 10mb size. she is not connect to the application but when she click on the worskheets on her excel file, it takes seve

  • Tables where the XI Data is stored

    Dear all, Can you let me know all the tables in XI in which the data is stored. Like where the asyncronous messages are stored(which table and what is the abap program name which gets executed to store the message id's etc in the table). Pl list out