Solved

Need a vb script to get folder sizes for many projects on server.

Posted on 2014-03-31
3
695 Views
Last Modified: 2014-04-17
Need a vb script to get folder sizes for many projects on server. Need it to loop through the csv file for folder locations and them produce a csv file with the folder location and the folder size.
0
Comment
Question by:williamfl
3 Comments
 
LVL 10

Expert Comment

by:Scott Thomson
Comment Utility
do you want just the main directory and all subdirectories tallies as 1 result

IE
- Gold
 - Real Gold
   - Really bright

Would you like the total size of Gold and all subdirectories
Or would you like each folder tallied individually?
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
'==========================================================================
' NAME: folderSize.vbs
' COMMENT: Scans folder sizes of a selected folder.
'==========================================================================
Dim objFSO, objFolder, objFile, objFile2, F, myVar1, myVar2, folderCount, strWrite

folderCount = 0
objFile2 = "folderdetails.csv"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Call browseFolder(strFolderSrc,"Source")
Set objFolder = objFSO.GetFolder(strFolderSrc)

'Write Header Row
Set objFile = CreateObject("Scripting.FileSystemObject")   
Set strWrite = objFile.OpenTextFile(objFile2, 2, True)
strWrite.WriteLine("Folder Name,Size (MB),# Files,# Sub Folders")
Wscript.Sleep 300

ShowFolderDetails objFolder

strWrite.Close

MsgBox "Complete."

Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set objFile2 = Nothing
Set F = Nothing
Set myVar1 = Nothing
Set myVar2 = Nothing
Set strWrite = Nothing

WScript.Quit
  
'==========================================================================
'Functions
Function ShowFolderDetails(oF)
    strWrite.WriteLine(oF.Name + "," + CStr(oF.Size /1024\1024) + "," + CStr(oF.Files.Count) + "," + CStr(oF.Subfolders.Count))

    'Comment out the following line and the loop to end the statement
    'to list all subfolders.(End Loop is 6 lines down)
    Do While folderCount < 1
    	for each F in oF.Subfolders
        	ShowFolderDetails F
    	Next
    	folderCount = folderCount + 1
    Loop
End Function

' browseFolder brings up the selection box to choose both the source and the destination.
Function browseFolder(myVar1,myVar2)
	Const WINDOW_HANDLE = 0
	Const NO_OPTIONS = 0
	Set objShell = CreateObject("Shell.Application")
	Set objFolder = objShell.BrowseForFolder _
    	(WINDOW_HANDLE, "Select a " & myVar2 & " folder:", NO_OPTIONS, "C:\Scripts")
	On Error Resume Next
	Set objFolderItem = objFolder.Self
	objPath = objFolderItem.Path
	myVar1 = objPath
	Call objPathChk(myVar1)
End Function

' objPathChk checks to make sure that a source has been selected.
Function objPathChk(myVar1)
	If myVar1 = "" Then
		MsgBox "Scan Folder Not Specified." & VbCrLf & _
				"Scan will now quit.", vbOKOnly, "Terminate"
		WScript.Quit
	End If		
End Function
'==========================================================================

Open in new window


http://community.spiceworks.com/scripts/show/824-get-folder-size-csv
0
 

Author Comment

by:williamfl
Comment Utility
The good news we pull the folder locations from a database.  So we have the folder direct share locations. So we would like to just do direct targeted folder locations. We are just want get the actual folder size for the trgeted folder. (//testfolder/project1)
The problem we are trying to resolve is we have 1000’s of project folders that grow intermittently some even out of control. The folders are part of an applications repository.  So this is not a traditional file store with independent security. The application governs everything.
If we use traditional tools like site scope directory monitors is scans to much information and can days on the folder with millions of files just to get total. If I use a simple VB script just ot get only folder size it just takes minutes.  We are planning creating a custom sitescope monitor to just get folder size but until then then just use a basic vbscript to get data for now.

I will try to the above suggestion.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now