Solved

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

Posted on 2014-03-31
3
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Expert Comment

by:Scott Thomson
ID: 39968501
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 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39968600
'==========================================================================
' 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
ID: 39969709
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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 video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 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