Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
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"
C:\test>du -sk c:\tmp28 c:\tmp
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
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 ?
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).
du .... | gawk "{total+=$1}END{print \"total size: \"total }"
Install the Unix OS and the du -sk command will be available.
@echo offsetlocalset /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
Hi Sidewinder I copy the code to notpad , rename vbs extention, run it. The window pop up error:invalid character source vbscript compilation error
This is a batch solution
What can I solve the problem
Code 80070006
But the script is vbsI rename to cscript.vbs. run in command prompt. the same symptoms
But the script is vbs
cscript //nologo Myscript.vbs
If the size is output to file which is txt or csv format and bytes to Megabytes. How can I do that
Const ForAppending = 8Set 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
c:\document and setting\administrator: 10,182,572,281 MBThe output is C:\Documents and Settings\Administrator 9710.8577
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
C:\Temp>cscript untitled.vbsMicrosoft (R) Windows Script Host Version 5.7Copyright (C) Microsoft Corporation. All rights reserved.Please enter directory name: d:\wfc\testlibD:\WFC\Testlib: 1.6922 MBC:\Temp>type dirsize.csvD:\WFC\Testlib,1.6922
WScript.Echo f.Path & ": " & FormatNumber((f.Size / 1048576),4,,TriStateTrue) & " MB"
fs.WriteLine f.Path & "," & Replace(FormatNumber((f.Size / 1048576),4), ",", "")
Set fs = fso.OpenTextFile("c:\temp\DirSize.csv", ForAppending, True)
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
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.
Const ForAppending = 8Set 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.CloseSub 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 NextEnd SubFunction 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
batch arithmetic only deals with integers.
Are you programme ? You are specialist for vb script.