?
Solved

list of folders and contents size for a network share

Posted on 2011-09-27
12
Medium Priority
?
1,163 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 61

Accepted Solution

by:
Bill Prew earned 1000 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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
LVL 61

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 61

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 61

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 1000 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 61

Expert Comment

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

~bp
0

Featured Post

NEW Internet Security Report Now Available!

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out this quarters report on the threats that shook the industry in Q4 2017.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
WAP (Web Application Proxy) provides reverse proxy functionality for web applications in the corporate network which allows users on most devices to access internal web applications from external networks.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

579 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