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 37130 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 #15 on: July 14, 2010, 05:46:28 AM »
This thread is way past it's sell-by-date.

What can I solve the problem

If you are using the VBS solution, you need to follow the instructions in Post #1. If you are using the BAT solution you need to follow the instructions in Post #10. While the instructions are similar, they are not interchangeable.

If you are still having problems, please post the code you are using. Also show us how you are running the code. Both scripts are specifically writing to the console, so I'm not understanding how you got a pop-up error unless you ran the VBScript without specifying CScript and it defaulted to WScript.

 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 #16 on: July 14, 2010, 09:56:45 PM »
    Set fso = CreateObject("Scripting.FileSystemObject")

    Do
        WScript.StdOut.Write "\\HDC-NT-MAIL01\D$" :
        strFolder = WScript.StdIn.ReadLine
        If fso.FolderExists(strFolder) Then
       Exit Do
        Else
         WScript.StdOut.Write "Invalid Directory ... Try Again" & vbCrLf
        End If
    Loop

    "Error window box messages"

    Line :4
    Char:5
    Error: The handle is invalid.
    Code: 80070006
    Source :(null)

       
    Set f = fso.GetFolder(strFolder)
    WScript.Echo f.Path & ": " & FormatNumber(f.Size,0,,TriStateTrue) & " bytes"





    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Batch file to check the folder size
    « Reply #17 on: July 15, 2010, 06:27:07 AM »
    This started out as such a simple request. The script prompted the user for a directory name and reported back the directory size.

    What is this: "\\HDC-NT-MAIL01\D$" : It looks like a UNC path, but in this context is used as a prompt.

    Let's get back to basics: Try copying and pasting the original code and let's get that running. We can make any changes later. The code is generic so it will run as is on any machine.

    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 prompt as:
    cscript scriptname.vbs Do not run with WScript as stdin and stdout are not supported.

    You also need to follow instructions. CScript does not produce popup errors; errors go to the console.

     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 #18 on: July 15, 2010, 10:49:55 PM »
      Hi Sidewinder

      I rename to vbs extention, copy the original code and run on the command prompt . the window message box show

      error: The handle is invalid
      Code 80070006
      Source (null)

      May I know what is the problem issue


      Salmon Trout

      • Guest
      Re: Batch file to check the folder size
      « Reply #19 on: July 16, 2010, 12:13:54 AM »
      Code 80070006

      You are running the script with wscript.exe, which cannot use stdin and stdout. You need to run it with cscript.exe.



      sun_os

        Topic Starter


        Beginner

        Re: Batch file to check the folder size
        « Reply #20 on: July 16, 2010, 12:46:51 AM »
        But the script is vbs

        I rename to cscript.vbs. run in command prompt. the same symptoms

        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 #21 on: July 16, 2010, 02:23:35 AM »
        But the script is vbs

        I rename to cscript.vbs. run in command prompt. the same symptoms

        No. you aren't understanding.

        you are running the VBS script using the executable, wscript.exe.

        you need to use cscript.exe.
        I was trying to dereference Null Pointers before it was cool.

        sun_os

          Topic Starter


          Beginner

          Re: Batch file to check the folder size
          « Reply #22 on: July 16, 2010, 09:48:16 AM »
          You mean that I rename the exe extention and run, I try to rename, the same symptom message box pop up

          Salmon Trout

          • Guest
          Re: Batch file to check the folder size
          « Reply #23 on: July 16, 2010, 11:00:45 AM »
          Quote
          But the script is vbs

          For running vbs scripts, there are two (2) "script engines". One is called Wscript.exe and one is called Cscript.exe. If you just run a vbs script by clicking on it in Windows Explorer, you'll most likely get the default Wscript.exe script engine. You do not want this. This particular script will not work with Wscript. You need to run it with the Cscript script engine. Open a command prompt in the folder where the script is. Let's pretend the script is called Myscript.vbs. Either change the name to that or substitute the real name. Type the following and hit Enter:

          Code: [Select]
          cscript //nologo Myscript.vbs

          sun_os

            Topic Starter


            Beginner

            Re: Batch file to check the folder size
            « Reply #24 on: July 17, 2010, 11:04:50 PM »
            Dear All,

            I can run the command by cscript //d xxx.vbs , it show the size in bytes.

            If the size is output to file which is txt or csv format and bytes to Megabytes.   How can I do that

            Could you give me th link to learn the cscript

            Thanks  ;D

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: Batch file to check the folder size
            « Reply #25 on: July 19, 2010, 05:51:38 AM »
            If the size is output to file which is txt or csv format and bytes to Megabytes.   How can I do that

            Part of the problem is that your specs are not clear. Which do you want, a txt file or a csv file? In addition to the onscreen display, the following snippet will produce a csv file. Each time you run the script, an additional entry will be appended to the csv file.

            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 & ": " & FormatNumber((f.Size / 1048576),4,,TriStateTrue) & " MB"
            fs.WriteLine f.Path & "," & Replace(FormatNumber((f.Size / 1048576),4), ",", "")
            fs.Close

            Could you give me th link to learn the cscript

            CScript is an engine that interprets VBScripts (among others) and runs them within the cmd console

            WScript is an engine that interprets VBScripts (among others) and runs them within Windows.

            VBScript is a language you use to write scripts which in turn can be run by CScript or WScipt.  Start here for a VBScript reference. Of course you can always ask questions on the forum, just be more specific as to what you need.

            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 #26 on: July 19, 2010, 08:59:40 AM »
              Hi Sidewinder

              Thank you for your help

              I run the program and check the csv format
              but the file size has difference

              e.g.

              c:\document and setting\administrator>cscript //d check.vbs

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

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

              Anything I can edit the code

              Thank you much



              nuckinfutz



                Greenhorn

                Re: Batch file to check the folder size
                « Reply #27 on: July 19, 2010, 09:14:47 AM »
                Follow up question for all.

                I too do not have much experience with batch files, but i am learning. the dilemma i am having is similar to the original poster?

                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

                ghostdog74



                  Specialist

                  Thanked: 27
                  Re: Batch file to check the folder size
                  « Reply #28 on: July 19, 2010, 09:25:48 AM »
                  see my first post. Use du with -H for human readable file size.

                  nuckinfutz



                    Greenhorn

                    Re: Batch file to check the folder size
                    « Reply #29 on: July 19, 2010, 09:39:01 AM »
                    ghostdog74,

                    thank you for the reply, however, i am in a situation where i cannot download anything to be put on the computers where i will need to run this batch file.

                    any other thoughts?

                    thanks,

                    NF