Solved

list of folders and contents size for a network share

Posted on 2011-09-27
12
946 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 51

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
 
LVL 51

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 51

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 51

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 51

Expert Comment

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

~bp
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
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 video discusses moving either the default database or any database to a new volume.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now