Solved

list of folders and contents size for a network share

Posted on 2011-09-27
12
966 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:ee-gd
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36710577
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"
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 36716847
This should be pretty close to what you are looking for, it's a VBS script, save as a VBS file and then run like:

cscript //nologo EE27343768.vbs > output.csv

sFolder = "c:\ee"

Set oFS = WScript.CreateObject("Scripting.FileSystemObject")

ShowFolderDetails oFS.GetFolder(sFolder)

Sub ShowFolderDetails(oFolder)
   Wscript.echo oFolder.Path & "," & Round(oFolder.Size / 1024 / 1024, 2)
   For Each oSubFolder In oFolder.Subfolders
      ShowFolderDetails(oSubFolder)
   Next
End Sub

Open in new window

~bp
0
 

Author Comment

by:ee-gd
ID: 36957708
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

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 36957876
@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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36957907
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.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36957946
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
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36958051
Or I guess for that matter what about DU -v ?

~bp
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36958091
That sounds like a very cool batch file project.

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

Cheers,
Rene
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36958262
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

0
 
LVL 10

Assisted Solution

by:ReneGe
ReneGe earned 250 total points
ID: 36958278
Oups, forgot to add /S in line 8.

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

REM SCANNING ROOT FOLDER
	FOR /F "tokens=3" %%A IN ('DIR /S "%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

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 37044927
Glad I could help, and thanks for the points!

Cheers,
Rene
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37046399
Glad that was useful.

~bp
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A brief introduction to what I consider to be the best editor for PowerShell.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question