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

Author Topic: Batch file to determine size of multiple folders and add the results  (Read 12582 times)

0 Members and 1 Guest are viewing this topic.

nuckinfutz

    Topic Starter


    Greenhorn

    Hi all... starting this new thread as directed.

    here is what i need help with:

    i need to write a batch file (preferably .bat not .vbs) that will give me the folder size of multiple directories including all sub-files and folders in MB or GB and i would like it to total the sizes. i do not need it to create an out.txt file with the results. on screen display would be fine.

    any and all help is appreciated.

    thank you,

    NF

    Dusty



      Egghead

    • I could if she would, but she won't so I don't.
    • Thanked: 75
    • Experience: Beginner
    • OS: Windows XP
    Re: Batch file to determine size of multiple folders and add the results
    « Reply #1 on: July 20, 2010, 02:51:18 AM »
    Because the command shell cannot handle floating point calculations the end-result could be many GB less than actual.  Can you accept a batch script using VBS for the evaluations?

    One good deed is worth more than a year of good intentions.

    cendel

    • Guest

    nuckinfutz

      Topic Starter


      Greenhorn

      Re: Batch file to determine size of multiple folders and add the results
      « Reply #3 on: July 20, 2010, 07:36:16 AM »
      Dusty,

      i was afraid that would be a limitation with a .bat file.

      Yes, i can accept a vbs for evaluations.

      thank you,

      NF


      nuckinfutz

        Topic Starter


        Greenhorn

        Re: Batch file to determine size of multiple folders and add the results
        « Reply #4 on: July 20, 2010, 10:18:08 AM »
        all,

        after Dusty's post, i decided to give up on the .bat file and started looking at .vbs. with some help this is what i came up with, and it works to show me the total size of a directory, and then display total size of a second directory, how can i modify this to show me the size in MB or GB and give me a grand total at the end.
        honestly, i dont need the individual results, but only the grand total window with the results would be preferred.

        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFolder = objFSO.GetFolder("D:\FOLDERNAME")
        wscript.Echo "Size: " & objFolder.Size
        Set objFolder = objFSO.GetFolder("D:\FOLDERNAME")
        wscript.Echo "Size: " & objFolder.Size


        of course replace FOLDERNAME with the name of the folder to view the size of.

        I am at the infant stages of learning .vbs so any help would be appreciated.

        thanks again all

        NF

        Salmon Trout

        • Guest
        Re: Batch file to determine size of multiple folders and add the results
        « Reply #5 on: July 20, 2010, 01:12:54 PM »
        Code: [Select]
        Set objFSO = CreateObject("Scripting.FileSystemObject")

        Totalbytes = 0

        ' Using hard coded folder names

        Set objFolder = objFSO.GetFolder("F:\Download\Alacarta\Programas")

        Totalbytes = Totalbytes + objFolder.Size

        Set objFolder = objFSO.GetFolder("F:\Download\App-install")

        Totalbytes = Totalbytes + objFolder.Size

        Set objFolder = objFSO.GetFolder("F:\Download\usenet")

        Totalbytes = Totalbytes + objFolder.Size

        wscript.echo "Crude Number Representation"
        wscript.echo
        wscript.echo "Total size = " & Totalbytes & " bytes"
        wscript.echo "Total size = " & (Totalbytes/1024) & " KB"
        wscript.echo "Total size = " & (Totalbytes/(1024*1024)) & " MB"
        wscript.echo "Total size = " & (Totalbytes/(1024*1024*1024)) & " GB"
        wscript.echo

        ' I suspect that you will not require to see the max number of decimal places
        ' so here's how to format the number
        ' change false to true and see what happens...

                      DecimalPlaces = 2
                IncludeLeadingDigit = False
        UseParensForNegativeNumbers = False
                        GroupDigits = False

        wscript.echo "Formatted Number Representation"
        wscript.echo
        wscript.echo "Total size = " & Formatnumber((Totalbytes/1024), DecimalPlaces, IncludeLeadingDigit, UseParensForNegativeNumbers , GroupDigits) & " KB"
        wscript.echo "Total size = " & Formatnumber((Totalbytes/(1024*1024)), DecimalPlaces, IncludeLeadingDigit, UseParensForNegativeNumbers , GroupDigits) & " MB"
        wscript.echo "Total size = " & Formatnumber((Totalbytes/(1024*1024*1024)), DecimalPlaces, IncludeLeadingDigit, UseParensForNegativeNumbers , GroupDigits) & " GB"


        nuckinfutz

          Topic Starter


          Greenhorn

          Re: Batch file to determine size of multiple folders and add the results
          « Reply #6 on: July 20, 2010, 02:07:24 PM »
          Salmon Trout,

          YOU ROCK!!!!!

          exactly what i needed.

          thank you very much.

          now as I am at "infant level" when it comes to VB knowledge, can you suggest some good sites where i can learn more about VB scripting and how to do it all.

          thanks,

          NF

          Salmon Trout

          • Guest
          Re: Batch file to determine size of multiple folders and add the results
          « Reply #7 on: July 20, 2010, 03:47:00 PM »
          can you suggest some good sites where i can learn more about VB scripting

          Anybody who is thinking of learning some VBScript should download and use the Microsoft Scripting help file, script56.chm which you can get here

          http://www.microsoft.com/downloads/details.aspx?familyid=01592c48-207d-4be1-8a76-1c4099d7bbb9&displaylang=en

          As for websites, there are MANY but these are some I have found useful:

          This one is very good

          Devguru main page

          http://www.devguru.com/technologies/vbscript/home.asp

          Devguru index of topics

          http://www.devguru.com/Technologies/vbscript/quickref/vbscript_list.html

          Microsoft VBScript reference:

          http://msdn.microsoft.com/en-us/library/d1wf56tt%28VS.85%29.aspx

          Another VBS reference:

          http://www.adminscripteditor.com/syntax.asp?l=v&lim=1

          Function reference

          http://www.w3schools.com/VBscript/vbscript_ref_functions.asp

          VBScript forum, FAQ etc

          http://www.tek-tips.com/threadminder.cfm?pid=329


          ghostdog74



            Specialist

            Thanked: 27
            Re: Batch file to determine size of multiple folders and add the results
            « Reply #8 on: July 20, 2010, 06:43:13 PM »
            download coreutils if you can. then just simply use the du command
            Code: [Select]
            C:\test>du -sh c:\folder
            the -h option means display the size in human readable format, ie MB, KB.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Batch file to determine size of multiple folders and add the results
            « Reply #9 on: July 20, 2010, 07:08:34 PM »
            I wrote this yesterday when this thread only had dusty's response, but decided to wait to post it until the OPsaid they could use a VBScript. It's similar in many ways to Salmon Trout's except that the folder names are accepted from the command line rather then hard coded. The "FormatSize" Function is a heavily modified version of the one in my File Library.

            Also, I had completely forgotten that the Size property of a folder worked to recursively acquire the entire folder's size. I originally had a routine that was doing so manually, but I have modified it since.


            Code: [Select]
            Public Function FormatSize(ByVal Bytes)
              Dim lookupprefix()
               


                    ReDim LookupPrefix(8)
                    LookupPrefix(0) = " Bytes"
                    LookupPrefix(1) = "KB"
                    LookupPrefix(2) = "MB"
                    LookupPrefix(3) = "GB"
                    LookupPrefix(4) = "TB"
                    LookupPrefix(5) = "PB"
                    LookupPrefix(6) = "EB"
                    LookupPrefix(7) = "ZB"
                    LookupPrefix(8) = "YB"
                   
                   
                   
                   

                currval = Bytes
                Do Until currval < 1024
                    currval = currval / 1024
                    countdiv = countdiv + 1
                Loop

                buildstr = Trim(FormatNumber(Round(currval, 2)))
                buildstr = buildstr + " " + Lookupprefix(countdiv)
               
               

                FormatSize = buildstr



            End Function

            Set FSO = CreateObject("Scripting.FileSystemObject")
            For Each argument in WScript.Arguments
                wpathname = argument
            WScript.Echo wpathname + ":" + FormatSize(FSO.GetFolder(wpathname).Size)

            Next


            I was trying to dereference Null Pointers before it was cool.