Solved

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

Posted on 2014-03-31
3
701 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
If not exist vbs error 4 47
Make a file test.vbs using vbscript 5 69
Using MS Code on my Mac 6 67
Problem to cell option 1 28
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 is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

808 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