Anda di halaman 1dari 2

'==========================================================================

' NAME: folderSize.vbs


' COMMENT: Scans folder sizes of a selected folder.
'==========================================================================
Dim objFSO, objFolder, objExcel, row, F, myVar1, myVar2, folderCount
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
folderCount = 0
row = 2
''remove comment from next line for a browse to select folder option
Call browseFolder(strFolderSrc,"Source")
''remove comment from next line if you want a box you can type a path into
''for remote network drives use \\computername\sharename or C$
'strFolderSrc = InputBox("Type in the folder path" , "Enter path")
Set objFolder = objFSO.GetFolder(strFolderSrc)
'Write Header Row
Set objExcel = CreateObject("Excel.application")
objExcel.Workbooks.add
objExcel.Cells(1, 1).Value = "Folder Name"
objExcel.Cells(1, 2).Value = "Size (MB)"
objExcel.Cells(1, 3).Value = "# Files"
objExcel.Cells(1, 4).Value = "# Sub Folders"
objExcel.Visible = True
Wscript.Sleep 300
ShowFolderDetails objFolder, row
'Uncomment the following 2 lines to save and quit Excel on completion.
'objExcel.ActiveWorkbook.SaveAs("C:\\FolderReport.xlsx")
'objExcel.Quit
MsgBox "Complete."
Set objFSO = Nothing
Set objFolder = Nothing
Set objExcel = Nothing
Set row = Nothing
Set F = Nothing
Set myVar1 = Nothing
Set myVar2 = Nothing
Set folderCount = Nothing
WScript.Quit

'==========================================================================
'Functions
Function ShowFolderDetails(oF,r)
On Error Resume Next
objExcel.Cells(row, 1).Value = oF.Name
objExcel.Cells(row, 2).Value = oF.Size / 1024 / 1024
objExcel.Cells(row, 3).Value = oF.Files.Count
objExcel.Cells(row, 4).Value = oF.Subfolders.count
row = row + 1
'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, row
Next
folderCount = folderCount + 1
Loop
End Function
' browseFolder brings up the selection box to choose both the source and the des
tination.
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:\\Scri
pts")
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
'==========================================================================

Anda mungkin juga menyukai