[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1927
  • Last Modified:

Script help, vbscript to get directory sizes and output to csv

I have found  scripts that are similar to what I want to do, but none work exactly as needed.  I just want the script to get a list of the of directories within a specified directory and there respective size then print that data to a csv/excel file

Script 1

'========================
'
' Title: Folder Size Checking Script
'
' Filename: fldrsize.vbs
' Author: Ariston Collander, Cox Computer Service
' Date: 03/2/2004
'
'========================

'###BEGIN Main####
On Error Resume Next

'==DIM Needed Variables==
Dim CurrentDate
Dim Company
Dim resultsfile
Dim FSO
Dim res
Dim varFldr, varFldrName, varFldrSize

'==Configure User defined Variables==
CurrentDate = Now
Company = "Insert Company Name Here"
resultsfile = "C:\Documents and Settings\rsreese\Desktop\tmp\" & FormatDateTime(CurrentDate, vbLongDate) & ".htm "

'==System variables - Do Not Change==
const HKEY_LOCAL_MACHINE = &H80000002
ForWriting = 2
forReading = 1
forWriting = 2
forAppending = 8
CutOff = Date() - 1

'==Create the Folder List Arrays==
arrServer = Array("C:\Documents and Settings\rsreese\Desktop\tmp")

'==Create the file system object==
Set FSO = CreateObject("Scripting.FileSystemObject")

'==Create the basic htm file==
Set res = FSO.CreateTextFile(resultsfile, True)
res.Writeline ("<html>")
res.Writeline ("<h1>Folder Size Verification results on: <font color='#000080'>" & date() & "</font></h1>")
res.Writeline ("<table BORDER=0 width=50% cellspacing=0 cellpadding=0>")

'==Add header for Server==
insertHTML("Insert Server Name Here")

'==Run the chkfldrspace() subroutine on Server Array==
chkfldrspace(arrServer)

'==Script complete==
res.Writeline ("</html>")
'####END Main####

'####Check Folder Space Subroutine####
Sub chkfldrspace (arrObject)

'==Cycle through the array to run the subroutine==
Dim varFolder
For each varFldr in arrObject
Set varFolder = FSO.GetFolder(varFldr)
varFldrSize = Round(varFolder.size/1048576, 2)

'==Write the results to the HTM file==
res.Writeline ("<tr>")
res.Writeline ("<td><b><font face=Verdana color=#000080 size=2> " & UCase(varFolder.Name) & "</font></b></TD>")
res.Writeline ("<td><b><font face=Verdana color=#000080 size=2> " & varFldrSize & " megabytes used</font></b></TD>")
res.Writeline ("</tr>")
Next

End Sub
'####End Check Folder Space Subroutine####

'####Insert HTML Header Subroutine####
Sub insertHTML(varSrvName)

res.Writeline ("<tr>")
res.Writeline ("<th colspan=2 bgcolor=#000080")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=Verdana size=4 color=#FFFFFF>Folder size information on " & varSrvName & " </font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<td bgcolor=#C0C0C0><b><font face=Verdana color=#FFFFFF size=3><u>Folder Name</u></font></b></TD>")
res.Writeline ("<td bgcolor=#C0C0C0><b><font face=Verdana color=#FFFFFF size=3><u>Folder Size</u></font></b></TD>")
res.Writeline ("</tr>")

End Sub
'####End Insert HTML Header Subroutine####
0
adamshields
Asked:
adamshields
1 Solution
 
harnalCommented:
Here you go.  Just change the paths that I've noted to the locations you want.

'--------------------------CUT-----------------------------
Option Explicit
 
  'Edit your folder path here.  The
  'script will enumerate all sub directories
  'under this folder.
  '-----------------------------------
  Dim fPath: fPath="c:\development\"  
  '-----------------------------------
 
  'This is the path where the CSV file will be created.
  'Change this to suit your needs.
  '---------------------------------------------------
  dim fileOut: fileOut="c:\Folders.csv"
  '---------------------------------------------------
 
 
  function getFolderMetrics()
   
    Dim fso
    Set fso=CreateObject("scripting.filesystemobject")
 
    Dim fldrObj, oFolders, f
   
    Set fldrObj = fso.GetFolder(fPath)
    Set oFolders=fldrObj.SubFolders
 
    dim fStream
    set fStream=fso.createTextFile(fileOut, true)
   
      For Each f In oFolders      
        fStream.writeline f.name & "," & f.size            
      Next
     
        fStream.close
   
    set fso=nothing
  end function
 
  getFolderMetrics()

'----------------------END CUT-----------------------------
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now