Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

807 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