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 37118 times)

0 Members and 1 Guest are viewing this topic.

sun_os

    Topic Starter


    Beginner

    Batch file to check the folder size
    « on: July 02, 2010, 04:16:33 AM »
    Hello All,

    I don't have programming background , but I need to write the vbs / batch file to check the folder size and display the size

    May I know what is the syntax to do ? >:(


    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Batch file to check the folder size
    « Reply #1 on: July 02, 2010, 08:00:35 AM »
    This is a VBS solution. You will be prompted for the directory name.

    Code: [Select]
    Set fso = CreateObject("Scripting.FileSystemObject")

    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 & ": " & FormatNumber(f.Size,0,,TriStateTrue) & " bytes"

    Save the script with a VBS extension and run from the command line as:
    cscript scriptname.vbs Do not run with WScript as stdin and stdout are not supported.

    The can also be done with a batch file by scraping the folder size off a directory listing but the VBS solution is so much more elegant. ;D
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    ghostdog74



      Specialist

      Thanked: 27
      Re: Batch file to check the folder size
      « Reply #2 on: July 07, 2010, 08:44:42 PM »
      download coreutils if you can. then just simply use the du command
      Code: [Select]
      C:\test>du -sk c:\tmp
      28      c:\tmp

      marvinengland



        Hopeful

        Thanked: 11
        Re: Batch file to check the folder size
        « Reply #3 on: July 08, 2010, 11:16:07 AM »
        Hello All,

        I don't have programming background , but I need to write the vbs / batch file to check the folder size and display the size

        May I know what is the syntax to do ? >:(



        Install the Unix OS  and the du -sk command will be available.
        USA

        Salmon Trout

        • Guest
        Re: Batch file to check the folder size
        « Reply #4 on: July 08, 2010, 11:21:48 AM »
        Install the Unix OS

        But then he can't run a batch file. Marvin just gets dumber and dumber.

        marvinengland



          Hopeful

          Thanked: 11
          Re: Batch file to check the folder size
          « Reply #5 on: July 08, 2010, 11:19:51 AM »

          I don't have a programming background , but I need to write the vbs / batch file to check the folder size and display the size

          May I know what is the syntax to do ? >:(



          http://en.wikipedia.org/wiki/Dual_boot

          We can have more than one OS installed on our machine.

          "Multi boot
          From Wikipedia, the free encyclopedia  (Redirected from Dual boot)
          Jump to: navigation, search
          "Multiboot" redirects here. For the specification, see Multiboot Specification.
           This article does not cite any references or sources.
           
          GRUB, with entries for Ubuntu and Windows Vista, an example of dual bootingMulti-boot or Multi-booting is the act of installing multiple operating systems on a computer, and being able to choose which one to boot when starting the computer. The term dual-booting refers to the common configuration of exactly two operating systems. Multi-booting requires a program called a boot loader."


          http://en.wikipedia.org/wiki/Dual_boot
          USA

          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 check the folder size
          « Reply #6 on: July 08, 2010, 11:37:15 AM »
          Marvin apparently doesn't realize that installing a separate OS doesn't give the previous OS the magical ability to use commands and features from the second OS.

          perhaps Marvin should actually learn about the concepts he suggests rather then copy-pasting directly from wikipedia.

          Perhaps Marvin can suggest a place to get this "UNIX" OS, which to my understanding was not necessarily available on the desktop market as he implies? Perhaps Marvin should read about the definition of the term "LINUX variant" to which he is clearly referring?

          Perhaps Marvin should not give a solution when the same solution has already been offered? Ghostdog already provided the information regarding the "du" command, and also provided a link that would allow this "du" program to run on a windows System. Did Marvin not read previous posts? Perhaps reading previous posts has become difficult for Marvin?


          Anyway, nonsense aside, I prefer the VBS solution, because it requires nothing to be downloaded. The du solution is much shorter. clearly it depends on the particular needs. The requirements state that the size is to be displayed, but make no mention that the filename itself, which is shown from the du output, should be. (I imagine there is a switch or possibly some other modification that could be made to supress it).
          I was trying to dereference Null Pointers before it was cool.

          ghostdog74



            Specialist

            Thanked: 27
            Re: Batch file to check the folder size
            « Reply #7 on: July 08, 2010, 01:50:07 PM »
            because it requires nothing to be downloaded.
            GNU tools only need to be downloaded once. They are just .exe executables

            Quote
            The du solution is much shorter. clearly it depends on the particular needs. The requirements state that the size is to be displayed, but make no mention that the filename itself, which is shown from the du output, should be. (I imagine there is a switch or possibly some other modification that could be made to supress it).
            du already comes with various features and switch options eg to display human readable file size, or you can decide to follow shortcuts or not, among others. du has been used in the Unix world for decades. If OP does not need the file names, simply pipe to sed/awk to remove. It is definitely not a big issue.
            Code: [Select]
            du ....  | gawk "{total+=$1}END{print \"total size: \"total }"

            I am not saying these can't be done with vbscript, just that i like the conciseness.

            ghostdog74



              Specialist

              Thanked: 27
              Re: Batch file to check the folder size
              « Reply #8 on: July 08, 2010, 01:53:46 PM »
              Install the Unix OS  and the du -sk command will be available.
              you do not need to install an entire OS to use du. du is just  a program, and Unix tools have already been ported to run on Windows.

              sun_os

                Topic Starter


                Beginner

                Re: Batch file to check the folder size
                « Reply #9 on: July 08, 2010, 10:21:43 PM »
                Thank for all reply the question and suggestion

                Acutally, I run the bat file to check the file size as I need to get the size to determine the Microsoft window KBXXX is not used up the workstation disk size.

                I thnk the bat file script is the best to do that, if I don't want to install the package, just write the script. How can I do that ? ;D


                Sidewinder



                  Guru

                  Thanked: 139
                • Experience: Familiar
                • OS: Windows 10
                Re: Batch file to check the folder size
                « Reply #10 on: July 09, 2010, 12:03:38 AM »
                The VBS solution posted earlier did not require you to install or download anything. All you needed to do was copy/paste the code into your editor, save the file and run according to the instructions.

                This is a batch solution. Same instructions: copy/paste into your editor (notepad is fine), save the file with a bat extension and run from the command prompt using the name you saved it with. You will be prompted for the directory name at runtime.

                Code: [Select]
                @echo off
                setlocal
                set /p dirName=Enter Directory Name:

                for %%v in ("%dirName%") do (
                  if not exist %%~sv\nul echo "%dirName%" is NOT a directory & goto :eof
                )

                for /f "tokens=3-4" %%v in ('dir "%dirName%" /s ^| find /i "file(s)"') do (
                  set bytes=%%v


                echo Folder: %dirName% contains %bytes% bytes

                 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 #11 on: July 11, 2010, 02:22:52 AM »
                  That fine ! Thank for you recommediation

                  I will try to use the script, thank for you helpful  ::)

                  sun_os

                    Topic Starter


                    Beginner

                    Re: Batch file to check the folder size
                    « Reply #12 on: July 11, 2010, 09:57:29 PM »
                    Hi Sidewinder

                    I copy the code to notpad , rename vbs extention, run it. The window pop up error:
                    invalid character  source vbscript compilation error

                    By the way, I want to check the folder size and output to xls / cvs

                    What is the code I need to fill in to exist code

                    Thanks

                    Salmon Trout

                    • Guest
                    Re: Batch file to check the folder size
                    « Reply #13 on: July 12, 2010, 12:10:40 AM »
                    Hi Sidewinder

                    I copy the code to notpad , rename vbs extention, run it. The window pop up error:
                    invalid character  source vbscript compilation error

                    Quote from: sidewinder
                    This is a batch solution

                    sun_os

                      Topic Starter


                      Beginner

                      Re: Batch file to check the folder size
                      « Reply #14 on: July 14, 2010, 01:33:09 AM »
                      What can I solve the problem