Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script for folder size

Status
Not open for further replies.

Transform85

Technical User
Feb 17, 2009
3
NZ
I currently have a script that will tell me the size of all folders in the directory below the specified folder.

Eg
+ Main Folder
- Folder 1
- Folder 2
-etc

The output is an excel spreadsheet however I would like it in text format. Does anyone know where I can find such a script?
 
If you simply want to dump it to a basic text file...FileSystemObject, OpenTextFile, WriteLine

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Why not simply save the generated spreadsheet as text file ?
 
Not tested, but what dm4ever suggested would look something like this (this would both save to spreadsheet and text file.)
Code:
'Run checkfolder

   [COLOR=blue]Dim fso, oResults
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set oResults = fso.CreateTextFile("c:\results.txt", True)[/color]
   CheckFolder (FSO.getfolder(rootfolder))
   [COLOR=blue]oResults.Close[/color]
Sub CheckFolder(objCurrentFolder)

       For Each objFolder In objCurrentFolder.SubFolders
         FolderSize = objFolder.Size
         Tmp = (FormatNumber(FolderSize, 0, , , 0)/1024)/1024
         [COLOR=blue]oResults.WriteLine(objFolder.Path & "," & Tmp)[/color]

         ObjXL.ActiveSheet.Cells(icount,1).Value = 
         ObjXL.ActiveSheet.Cells(icount,2).Value = Tmp
         'Wscript.Echo Tmp & " " & objFolder.Path
	 'raise counter with 1 for a new row in excel 
         icount = icount + 1
       Next

       'Recurse through all of the folders
       For Each objNewFolder In objCurrentFolder.subFolders
               CheckFolder objNewFolder
       Next
       
End Sub
 
What PHV suggested would require the least work

Use the SaveAs method and specify the format as
xlTextWindows = 20


--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I cannot use a spreadsheet because the server it will be ran on does not have msoffice and I don't want to install it just for this script. A text based with largest folders descending would be awesome!
 
You don’t need office on a Server have the script save the file to a shared folder and then open the file from the share from your desk. Normally you don’t want to access the server to even look at logs if you can do it remotely and securely you should be.

According to the script you can run that remotely also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top