ee-gd
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,100M b
\\nas\design\project1\subf older2, 123Mb etc
I need something like:
\\nas\design\project1,100M
\\nas\design\project1\subf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...
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
'==========================================================================
@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
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
http://www.microsoft.com/download/en/details.aspx?id=6732
~bp
Or I guess for that matter what about DU -v ?
~bp
~bp
That sounds like a very cool batch file project.
I have an idea. Will post when the basics are done!!
Cheers,
Rene
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help, and thanks for the points!
Cheers,
Rene
Cheers,
Rene
Glad that was useful.
~bp
~bp
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"