Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file to check the folder size  (Read 37123 times)

0 Members and 1 Guest are viewing this topic.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch file to check the folder size
« Reply #30 on: July 19, 2010, 11:43:22 AM »
@sun_os:

Where did this come from?

Quote
c:\document and setting\administrator: 10,182,572,281 MB

The output is C:\Documents and Settings\Administrator 9710.8577

Are you sure the 10,182,572,281 represents MB (which is an awful lot) or just bytes (more reasonable)

It turns out that 10,182,572,281 bytes is 9710.8577 MB. Imagine that!

The file size for both the onscreen display and the csv line are computed the same way. I cannot reproduce the error. Need more info.

@nuckinfutz :

Please start your own thread. This marathon thread has gone on for 29 posts with no end in sight. Your post is only complicating things.

 8)

The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

sun_os

    Topic Starter


    Beginner

    Re: Batch file to check the folder size
    « Reply #31 on: July 20, 2010, 07:37:35 AM »
    Hi Sidewinder,

    How can I start the New Thread here?

    Could you tell me, is that mean send you the personal messages ?

    I copy your code and run cscript //d check.vbs , check with csv format which is not match the console information




    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Batch file to check the folder size
    « Reply #32 on: July 20, 2010, 08:26:06 AM »
    How can I start the New Thread here?

    That was for nuckinfutz who tried to hijack your thread.

    Could you tell me, is that mean send you the personal messages ?

    No. I very rarely even check if I have messages much less answer them. I prefer to post solutions that everyone can read.

    I copy your code and run cscript //d check.vbs , check with csv format which is not match the console information

    I cannot reproduce your results:

    Quote
    C:\Temp>cscript untitled.vbs
    Microsoft (R) Windows Script Host Version 5.7
    Copyright (C) Microsoft Corporation. All rights reserved.

    Please enter directory name: d:\wfc\testlib
    D:\WFC\Testlib: 1.6922 MB

    C:\Temp>type dirsize.csv
    D:\WFC\Testlib,1.6922

    Unless I'm missing something, the console and the csv file matches. The only difference is the format of the output, but the data is the same. You wanted a csv file (comma separated values).

    CSV files are useful when you need to input the data into a spreadsheet or database program. They are also easy to parse.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    sun_os

      Topic Starter


      Beginner

      Re: Batch file to check the folder size
      « Reply #33 on: July 20, 2010, 09:25:23 AM »
      Hi
      I capture the screen shot for your reference

      C:\temp>cscript check.vbs
      Microsoft (R) Windows Script Host Version 5.6
      Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.


      Please enter directory name: c:\downloads
      C:\Downloads: 5,203,235,307 MB

      C:\temp>type disk*
      系統找不到指定的檔案。

      C:\temp>type dir*

      DirSize.csv

      C:\Documents and Settings\Administrator,9710.8577
      C:\Downloads,4962.1919
      C:\Downloads,4962.1919

      C:\temp>

      That is output

      Thanks

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Batch file to check the folder size
      « Reply #34 on: July 20, 2010, 10:51:53 AM »
      Please check your code. I'm not understanding any of this. It appears the line that produces the console output has a problem.

      The line produces the console output:
      Quote
      WScript.Echo f.Path & ": " & FormatNumber((f.Size / 1048576),4,,TriStateTrue) & " MB"

      This line produces the CSV file output:
      Quote
      fs.WriteLine f.Path & "," & Replace(FormatNumber((f.Size / 1048576),4), ",", "")

      Also check this line:
      Quote
      Set fs = fso.OpenTextFile("c:\temp\DirSize.csv", ForAppending, True)
      The above line shows the path to the CSV file. If you changed it that's fine as long as you know where the CSV file is.

      If this doesn't turn up anything, please post the script you are using. If you made any changes leave them in. Need to see the actual code that runs.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      sun_os

        Topic Starter


        Beginner

        Re: Batch file to check the folder size
        « Reply #35 on: July 20, 2010, 08:59:56 PM »
        Hi Sidewinder

        I run the same script on the another workstation, it is no problem on the size checking. I think something wrong on my workstation.

        Last time, I request to check the directory size, the code is focus on that. If the script can let me check the size of drive or directory folder option.  I need to use compond condition if....if.... then....elsif  condition

        Thanks

        sun_os

          Topic Starter


          Beginner

          Re: Batch file to check the folder size
          « Reply #36 on: July 21, 2010, 01:18:31 AM »
          Hi Sidewinder

          I run the same script on the another workstation, it is no problem on the size checking. I think it may be  something wrong with my workstation.

          Last time I have the problem on the script to do the check the size, but I get message from my boss, he needs to check the case is run the script can show all the size of directory at once.

          I check the all KB / MSI folder size under the directory e:\Patches$\KBXXXX\xxxxx and output to csv with the size, but it is different folder in the KBxxxx folder directory. The script is complex and need to to in effort to do that?

          Thanks





          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: Batch file to check the folder size
          « Reply #37 on: July 21, 2010, 08:21:39 AM »
          Glad to see you got the script working. Not sure what could have caused the error on you other machine. VBScript is very forgiving where objects and variables are destroyed when the script ends. An exception is application objects (Word, Excel, etc) where they must be Quit, otherwise you'll find them in your task list long after the script ends.

          Quote
          Last time I have the problem on the script to do the check the size, but I get message from my boss, he needs to check the case is run the script can show all the size of directory at once.

          Not sure what you're asking. I tweaked the script to display the subfolders. I also added a unit of measure to the CSV file so the numbers make more sense.

          Be aware that the FileSystemObject recurses the directory tree when computing the size property. Each folder size includes all of it's subfolders. The numbers you see are correct but may appear inflated.

          It's possible to retrieve the files from a recursive folder search, but the total size of the files will probably not add up to the size of the folder unless the folder has no subfolders. This would be easier in batch, however batch arithmetic only deals with integers. This can lead to some wildly inaccurate results. Hey! 700k bytes here, 700k bytes there, and pretty soon you're talking about some serious real estate. ;D

          Code: [Select]
          Const ForAppending = 8

          Set fso = CreateObject("Scripting.FileSystemObject")
          Set fs = fso.OpenTextFile("c:\temp\DirSize.csv", ForAppending, True)

          Do
              WScript.StdOut.Write "Please enter directory name: "
              strFolder = WScript.StdIn.ReadLine
              If fso.FolderExists(strFolder) Then
          Exit Do
              Else
            WScript.StdOut.Write "Invalid Directory ... Try Again" & vbCrLf
              End If
          Loop

          Set f = fso.GetFolder(strFolder)
          WScript.Echo f.Path & ": " & GetEditSize(f.Size)
          fs.WriteLine f.Path & "," & Replace(GetEditSize(f.Size), " ", ",")
          GetThePaths(f)

          fs.Close


          Sub GetThePaths(Folder)
            For Each Subfolder in Folder.SubFolders
          WScript.Echo SubFolder.Path & ": " & GetEditSize(SubFolder.Size)
              fs.WriteLine SubFolder.Path & "," & Replace(GetEditSize(SubFolder.Size), " ", ",")
          GetThePaths Subfolder
            Next
          End Sub

          Function GetEditSize(intSize)
          If intSize => (1024*1024*1024*1024) Then
          GetEditSize = Round(FormatNumber((intSize/(1024*1024*1024)), 4,, TriStateTrue), 2) & " TB"
          ElseIf intSize => (1024*1024*1024) Then
          GetEditSize = Round(FormatNumber((intSize/(1024*1024*1024)), 4,, TriStateTrue), 2) & " GB"
          ElseIf intSize => (1024*1024) Then
          GetEditSize = Round(FormatNumber((intSize/(1024*1024)), 4,, TriStateTrue), 2) & " MB"
          ElseIf intsize => 1024 Then
          GetEditSize = Round(FormatNumber((intSize/1024), 4,, TriStateTrue), 2) & " KB"
          Else
          GetEditSize = intSize & " Bytes"
          End If
          End Function

          I'm sure we'' here from you again. 8)
          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein

          Salmon Trout

          • Guest
          Re: Batch file to check the folder size
          « Reply #38 on: July 21, 2010, 08:33:58 AM »
          batch arithmetic only deals with integers.

          ... and runs out of steam at 2 G (32-bit signed integer)

          sun_os

            Topic Starter


            Beginner

            Re: Batch file to check the folder size
            « Reply #39 on: July 24, 2010, 04:06:43 AM »
            Hi Sidewinder, :D

            Great !

            I 'm appreciate your helpful and support the code. I can get the result what I want. 

            Are you programme ?  You are specialist for vb script. Except for Microsoft link, what is other link for script which is useful for beiginner.  VBscript. Batch , Shell script


            Thank you very much !   ;D

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: Batch file to check the folder size
            « Reply #40 on: July 24, 2010, 05:35:59 AM »
            Are you programme ?  You are specialist for vb script.

            I'm retired now after being in IT my entire career from EAM operator to systems administrator. Currently I run a small business in the local village helping some of the small business owners with their software needs and day to day PC operations.

            For batch coding I always recommend this site

            For VBScript check out this tutorial

            Also do a search on your hard drive for a file named script56.chm. This is a VBScript reference with lots of examples. Never leave home without it. ;D If you can't find it on your hard drive, you can download it from here

            Good luck.  8)

            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            sun_os

              Topic Starter


              Beginner

              Re: Batch file to check the folder size
              « Reply #41 on: July 24, 2010, 10:39:31 AM »

              I come from H.K. and work for system engineer.  My employment is only for the three months contract. The IT  in H.K. is no long term career, company prefer to recruit the outsource to support the inhouse I.T operation. 

              I have a dream to start the own business but it is a lot of competitor in Hong Kong. The profit margin is  not very good in Hong Kong.

              May I know where are you living ?


              Enjoy your life and retirement !