Home / Software / Computer programming / Batch file to check the folder size
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 3  All - (Bottom) Print
Author Topic: Batch file to check the folder size  (Read 5404 times)
sun_os
Topic Starter
Rookie



Posts: 30


« 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 ? >:(

IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,340

Experience: Familiar
OS: Windows 7

« 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
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
ghostdog74
Mentor



Thanked: 26
Posts: 1,511


« 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
IP logged

marvinengland
Hopeful



Thanked: 10
Posts: 258


« 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.
IP logged

USA
Salmon Trout
Sage



Thanked: 546
Posts: 7,947

Computer: Specs
Experience: Beginner
OS: Unknown

1
« 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.
IP logged


Proud to be European
marvinengland
Hopeful



Thanked: 10
Posts: 258


« 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
IP logged

USA
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,866

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« 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).
IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
ghostdog74
Mentor



Thanked: 26
Posts: 1,511


« 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.
IP logged

ghostdog74
Mentor



Thanked: 26
Posts: 1,511


« 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.
IP logged

sun_os
Topic Starter
Rookie



Posts: 30


« 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

IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,340

Experience: Familiar
OS: Windows 7

« 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)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
sun_os
Topic Starter
Rookie



Posts: 30


« 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  ::)
IP logged
sun_os
Topic Starter
Rookie



Posts: 30


« 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
IP logged
Salmon Trout
Sage



Thanked: 546
Posts: 7,947

Computer: Specs
Experience: Beginner
OS: Unknown

1
« 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
IP logged


Proud to be European
sun_os
Topic Starter
Rookie



Posts: 30


« Reply #14 on: July 14, 2010, 01:33:09 AM »

What can I solve the problem
IP logged
Pages: [1] 2 3  All - (Top) Print 
Home / Software / Computer programming / Batch file to check the folder size « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.121 seconds with 20 queries.