winwell1888
IS-IT--Management
Hello
I am involved in reducing e-waste for my company (wastage in terms of duplicate data, bad file structure, bad folder names, folder depths etc and the human waste in lost time trying find stuff etc).
So we would like to run a script on our root directories (we have loads of them) so establish the following information and present it in excel:
The folder structure and the size of each folder
The number of different file types and the size of each file type.
E.G. Directory A has 3 folders and each of them has multiple subfolders containg a mix of .doc, .xls and .ppt files.
The script would produce a report in excel something like this:
Directory A
10MB Folder1
30MB Folder2
50MB Folder3
7MB Folder1/sub1
3MB Folder1/sub1/sub2
and so on.
Then the file types
Folder 1
12 doc files 3MB
24 ppt file 4MB
35 xls files 3MB
and so on or somthing like that anyway.
At the end of the day, we would like to be able to understand what each directory looks like and suggest ways to improve the structure. So if we could show files stored 7, 8 9 folders deep for example, we could highlight that. We could also show the number & size of different file types. We would use windows explorer to look for duplicate files and/or large files and suggest ways to reduce them or delete if needbe. Then we could re run the script to monitor progress an dmaybe even calculate the savings in $ terms (assuming we can assign a value to a MB of server space)
I hope that makes sense?
We already have a script to produce the first part of the task (get folder size and structure and dump into excel) and I list that below. I don't know where that came from but it was found online somewhere and tweaked a bit).
it would be ideal if the file type part couldbe added into what we've already got if possible.
Run this for any folder and you'll see how it works
Any suggestions or ideas welcomed,
many thanks
I am involved in reducing e-waste for my company (wastage in terms of duplicate data, bad file structure, bad folder names, folder depths etc and the human waste in lost time trying find stuff etc).
So we would like to run a script on our root directories (we have loads of them) so establish the following information and present it in excel:
The folder structure and the size of each folder
The number of different file types and the size of each file type.
E.G. Directory A has 3 folders and each of them has multiple subfolders containg a mix of .doc, .xls and .ppt files.
The script would produce a report in excel something like this:
Directory A
10MB Folder1
30MB Folder2
50MB Folder3
7MB Folder1/sub1
3MB Folder1/sub1/sub2
and so on.
Then the file types
Folder 1
12 doc files 3MB
24 ppt file 4MB
35 xls files 3MB
and so on or somthing like that anyway.
At the end of the day, we would like to be able to understand what each directory looks like and suggest ways to improve the structure. So if we could show files stored 7, 8 9 folders deep for example, we could highlight that. We could also show the number & size of different file types. We would use windows explorer to look for duplicate files and/or large files and suggest ways to reduce them or delete if needbe. Then we could re run the script to monitor progress an dmaybe even calculate the savings in $ terms (assuming we can assign a value to a MB of server space)
I hope that makes sense?
We already have a script to produce the first part of the task (get folder size and structure and dump into excel) and I list that below. I don't know where that came from but it was found online somewhere and tweaked a bit).
it would be ideal if the file type part couldbe added into what we've already got if possible.
Run this for any folder and you'll see how it works
Any suggestions or ideas welcomed,
many thanks
Code:
Sub CheckFolder(objCurrentFolder)
on error resume next
For Each objFolder In objCurrentFolder.SubFolders
FolderSize = objFolder.Size
Tmp = (FormatNumber(FolderSize, 0, , , 0)/1024)/1024
ObjXL.ActiveSheet.Cells(icount,2).Value = objFolder.Path
ObjXL.ActiveSheet.Cells(icount,1).Value = Tmp
icount = icount + 1
Next
'Recurse through all of the folders
For Each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder
Next
End Sub
rootfolder = Inputbox("Enter DIR or folder path: "& chr(10) & "(Include trailing backslash at end of path)" & _
chr(10) & chr(10) & "(e.g.\\Server\DIR Name\Folder\etc\)" & chr(10) & chr(10), _
"Getfoldersize", "C:\temp\")
'Run checkfolder if something was entered in the CAF directory field, else just end
if rootfolder <> "" Then
outputfile = "C:\temp\foldersize_" & Day(now) & Month(now) & Year(now) & ".xls"
Set fso = CreateObject("scripting.filesystemobject")
if fso.fileexists(outputfile) then fso.deletefile(outputfile)
'Create Excel workbook
set objXL = CreateObject( "Excel.Application" )
objXL.Visible = False
objXL.WorkBooks.Add
'Counter 1 for writing in cell A1 within the excel workbook
icount = 1
'Run checkfolder
CheckFolder (FSO.getfolder(rootfolder))
'Lay out for Excel workbook
objXL.Range("A1").Select
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Columns(1).ColumnWidth = 21
objXL.Columns(2).ColumnWidth = 21
objXL.Columns(1).NumberFormat = "#,##0.0"
objXL.Range("A1").NumberFormat = "d-m-yyyy"
objXL.Range("A1:B9").Select
objXL.Selection.Font.Bold = True
objXL.Range("A1:B5").Select
objXL.Selection.Font.ColorIndex = 5
objXL.Range("B2").Select
objXL.Selection.Font.Italic = True
objXL.Selection.Font.Size = 16
ObjXL.ActiveSheet.Cells(1,2).Value = "DIR FolderSize and Folder Structure"
ObjXL.ActiveSheet.Cells(1,1).Value = Day(now) & "-" & Month(now) & "-"& Year(now)
ObjXL.ActiveSheet.Cells(2,1).Value = UCase(rootfolder)
ObjXL.ActiveSheet.Cells(3,1).Value = "Folders are separated by --> so they can be seen more easily"
objXL.ActiveSheet.Cells(5,1).Value = "Total DIR Size (MB)"
objXL.Range("B5").Select
objXL.Selection.HorizontalAlignment = -4108
objXL.Selection.Font.ColorIndex = 3
objXL.Range("B6").Select
objXL.Selection.HorizontalAlignment = -4108
objXL.Selection.Font.ColorIndex = 3
objXL.Selection.NumberFormat = "£#,##0.0"
objXL.Range("A9:B9").Select
objXL.Selection.Font.Bold = True
ObjXL.ActiveSheet.Cells(9,1).Value = "Total (MB)"
ObjXL.ActiveSheet.Cells(9,2).Value = "Folder"
objXL.Range("B:B").Replace rootfolder, ""' get rid of the \\IRF etc bit
objXL.Range("B:B").Replace "\", "-->" ' make it a bit easier to spot the folders
'Finally close the workbook
ObjXL.ActiveWorkbook.SaveAs(outputfile)
ObjXL.Application.Quit
Set ObjXL = Nothing
'Message when finished
Set WshShell = CreateObject("WScript.Shell")
Finished = Msgbox ("Script executed successfully, results can be found in " & Chr(10) _
& outputfile & "." & Chr(10) & Chr(10) _
& "Do you want to view the results now?", 65, "Script executed successfully!")
if Finished = 1 then WshShell.Run "excel " & outputfile
end if