Link to home
Start Free TrialLog in
Avatar of ee-gd
ee-gdFlag for United Kingdom of Great Britain and Northern Ireland

asked on

list of folders and contents size for a network share

I have a network folder(\\nas\design) that is over 4Tb in size and I need to compile a list(CSV) of all the folders and size of the files in them - any scripts you may have that do that?

I need something like:
\\nas\design\project1,100Mb
\\nas\design\project1\subfolder2, 123Mb etc
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you tried Tree Size ?  There is a free version and it does this v.well.

http://www.jam-software.com/treesize_free/

For 4Tb of data the other options of manual scripts are going to be slow, e.g. this one mine here:

e.g. http://scripts.dragon-it.co.uk/links/batch-subdir-folder-size

There used to be a MS tool from the resource kits I think it was called "dirsize.exe"
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ee-gd

ASKER

we are licensed for treesize professional, but the exports it allows are only on one level and does not include subfolders, which is what I need.

I have tried a number of scripts, but they all hang in a few hours and do not produce complete results...

Initially I tried using the filesystem object as suggested here, but again in about four hours the script stopped.

Lastly I amended the script as below, which instead of the file system object uses DU from sysinternals, but unfortunately again after outputting 33300 items the script stopped although producing more results than before...

I have not spent much more time on this, but I am thinking I probably need to work on error handling and check if there is something about the folder names it is encountering...


'==========================================================================
' NAME: get_folder_size(CSV).vbs
' COMMENT: Scans a network folder and produces a list of folders, size and files count
'==========================================================================
Dim objFSO, objFolder, strFolderSrc, objFile, strWrite, objFile2

Call FolderInput
objFile2 = "folderdetails_" + CStr(Replace(Date,"/","-")) + "_" + CStr(Replace(Time,":","-")) + ".csv"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolderSrc)

'Write Header Row
Set objFile = CreateObject("Scripting.FileSystemObject")   
Set strWrite = objFile.OpenTextFile(objFile2, 2, True)
strWrite.WriteLine("Folder,Size (MB),# Files")
Wscript.Sleep 300

GenFolderDetails objFolder

strWrite.Close

Set objFSO = Nothing
Set objFolder = Nothing
Set F = Nothing
WScript.Quit
  
'==========================================================================
'Functions
Function FolderInput()
	strFolderSrc=InputBox("Please enter path",,"\\srv-filer-1\design")
End Function

Function DU(input)
	Dim strCommand, objShell, objExec 
	strCommand = "%comspec% /c C:\Windows\System32\du.exe -n -q -accepteula """ & input & """"
  	Set objShell = CreateObject("WScript.Shell") 
  	Set objExec = objShell.Exec(strCommand) 
  	'We wait for the end of process
	Do While objExec.Status = 0
     	WScript.Sleep 100
	Loop
	DU = objExec.StdOut.ReadAll
End Function

Function StringToArray(input) 
	'converts the multi-line du output to an array so that it can be parsed line by line 
	StringToArray = Split(input,vbCrLf) 
End Function

Function GetSize(input) 
'cuts the preceeding & succeeding text, leaving just the size remaining in Mb
  Dim strSizeTrimedLeft 
    strSizeTrimedLeft = mid(input,(InStr(input,"disk:")+6)) 
  GetSize = Round(Replace(mid(strSizeTrimedLeft,1,(InStr(strSizeTrimedLeft," bytes")-1)),",","")/1024/1024,2)
End Function 

Function GetFiles(input)
	'cuts the preceeding, leaving just the number of files
  	Dim strFilesTrimedLeft 
    strFilesTrimedLeft = right(input,2) 
  	GetFiles = strFilesTrimedLeft
End Function

Function GenFolderDetails(oF)
    Dim strDUOutput, arrDUOutput, strSize, strFiles
    strDUOutput = DU(oF.Path)
	arrDUOutput = StringToArray(strDUOutput)
	If arrDUOutput(0) = "No matching files were found." Then
		strWrite.WriteLine(CStr(oF.Path) + ",0,0")
	Else
		strFiles = GetFiles(arrDUOutput(0))
		strSize = GetSize(arrDUOutput(3))
    	strWrite.WriteLine(CStr(oF.Path) + "," + CStr(strSize) + "," + CStr(strFiles))
	End If
	For Each F in oF.Subfolders
       	GenFolderDetails F
    Next
End Function
'==========================================================================

Open in new window

Avatar of Bill Prew
Bill Prew

@ee-gd

If you ran my script, and it stopped after 4 hours, but before you thought it should be done, then it should have displayed an error message.

~bp
I presume then the logical thing to do is start running your checks deeper into the tree, i.e. running one set of reports from \\server\share\project1 etc.
Have you tried DIRUSE from Microsoft, not quite CSV, but it is in a column format that Excel could easily manipulate.

http://www.microsoft.com/download/en/details.aspx?id=6732

~bp
Or I guess for that matter what about DU -v ?

~bp
That sounds like a very cool batch file project.

I have an idea. Will post when the basics are done!!

Cheers,
Rene
All you may have left to do, is some cosmetics.

Cheers,
Rene
@ECHO OFF
SETLOCAL enabledelayedexpansion
SET Size=0
SET PreviousLine=0
SET RootFolder=%~dp0

REM SCANNING ROOT FOLDER
	FOR /F "tokens=3" %%A IN ('DIR "%RootFolder%\*.*"') DO (
		SET Size=!PreviousLine!
		SET PreviousLine=%%A
	)
	SET RootSize=%Size%
	ECHO [%RootSize%] ROOT

REM SCANNING FOLDERS
	FOR /F "delims=" %%A IN ('DIR /B /AD /OG /S "%RootFolder%\*.*"') DO (
		FOR /F "tokens=3" %%A IN ('DIR "%%~dpnA\*.*"') DO (
			SET Size=!PreviousLine!
			SET PreviousLine=%%A
		)
	ECHO [!Size!] %%~dpnA
	)

PAUSE
EXIT

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad I could help, and thanks for the points!

Cheers,
Rene
Glad that was useful.

~bp