Hi
I wrote a code which scans subfolders and return the folder name and sizes. But the code is only going to 1st level of subfolders. is there anyway I can modify to go to indefinite levels.
The Code
--------
<%@ Language=VBScript %>
<%
Dim objFSO
Dim objFolder
Dim objItem
Dim strCount
Dim strSize
Dim strTotalCount
Dim strTotalSize
Dim strPath
Dim strFolderCount
strCount = 0
strSize = 0
strTotalCount = 0
strTotalSize = 0
strFolderCount = 1
strPath="\"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
response.write "<TABLE cellpadding='2'><tr><TD align='left' style='border-Bottom-style: solid'><font face='Tahoma' size='2'><strong>Folder Name</td></strong>" &_
"<TD align='right' style='border-Bottom-style: solid'><font face='Tahoma' size='2'><strong>Total Files</strong></TD><TD align='right' style='border-Bottom-style: solid'><font face='Tahoma' size='2'><strong>Folder Size</strong></TD></TR>"
'Loop to get all files in root directory
'---------------------------------------
For Each objItem In objFolder.Files
strCount=strCount+1
strSize=strsize + round(objItem.Size/1024,2)
Next
Response.write ("<TR><TD><b><p><font face='Tahoma' size='2'>" & objFolder.Path & "</b></TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strCount & " file(s)" & "</TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strSize & " KB" & "</TD></TR>")
strTotalCount=strCount
strTotalSize=strSize
strSize=0
strCount=0
'Loop to get all files in subfolders
'---------------------------------------
For Each objFolder in objFolder.SubFolders
For Each objItem in objFolder.Files
strCount=strCount+1
strSize=strsize + round(objItem.Size/1024,2)
Next
Response.write ("<TR><TD><p><b><p><font face='Tahoma' size='2'>" & objFolder.Path & "</b></TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strCount & " file(s)" & "</TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strSize & " KB" & "</TD></TR>")
strTotalCount=strTotalCount+strCount
strTotalSize=strTotalSize+strSize
strSize=0
strCount=0
strFolderCount=strFolderCount+1
Next
Response.write ("<TR><TD style='border-Top-style: solid'><p><b><p><font face='Tahoma' size='2'>Total " & strFolderCount & " folder(s) </TD>" &_
"<TD align='right' style='border-Top-style: solid'><font face='Tahoma' size='2'>" & strTotalCount & " file(s)" & "</TD>" &_
"<TD align='right' style='border-Top-style: solid'><font face='Tahoma' size='2'>" & strTotalSize & " KB" & "</TD></TR></Table>")
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
-------------------------------------------------------
Any suggestions?
Cheers!
ÙÇãá
It's important to learn the rules so that you know how to break them.
I wrote a code which scans subfolders and return the folder name and sizes. But the code is only going to 1st level of subfolders. is there anyway I can modify to go to indefinite levels.
The Code
--------
<%@ Language=VBScript %>
<%
Dim objFSO
Dim objFolder
Dim objItem
Dim strCount
Dim strSize
Dim strTotalCount
Dim strTotalSize
Dim strPath
Dim strFolderCount
strCount = 0
strSize = 0
strTotalCount = 0
strTotalSize = 0
strFolderCount = 1
strPath="\"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
response.write "<TABLE cellpadding='2'><tr><TD align='left' style='border-Bottom-style: solid'><font face='Tahoma' size='2'><strong>Folder Name</td></strong>" &_
"<TD align='right' style='border-Bottom-style: solid'><font face='Tahoma' size='2'><strong>Total Files</strong></TD><TD align='right' style='border-Bottom-style: solid'><font face='Tahoma' size='2'><strong>Folder Size</strong></TD></TR>"
'Loop to get all files in root directory
'---------------------------------------
For Each objItem In objFolder.Files
strCount=strCount+1
strSize=strsize + round(objItem.Size/1024,2)
Next
Response.write ("<TR><TD><b><p><font face='Tahoma' size='2'>" & objFolder.Path & "</b></TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strCount & " file(s)" & "</TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strSize & " KB" & "</TD></TR>")
strTotalCount=strCount
strTotalSize=strSize
strSize=0
strCount=0
'Loop to get all files in subfolders
'---------------------------------------
For Each objFolder in objFolder.SubFolders
For Each objItem in objFolder.Files
strCount=strCount+1
strSize=strsize + round(objItem.Size/1024,2)
Next
Response.write ("<TR><TD><p><b><p><font face='Tahoma' size='2'>" & objFolder.Path & "</b></TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strCount & " file(s)" & "</TD>" &_
"<TD align='right'><font face='Tahoma' size='2'>" & strSize & " KB" & "</TD></TR>")
strTotalCount=strTotalCount+strCount
strTotalSize=strTotalSize+strSize
strSize=0
strCount=0
strFolderCount=strFolderCount+1
Next
Response.write ("<TR><TD style='border-Top-style: solid'><p><b><p><font face='Tahoma' size='2'>Total " & strFolderCount & " folder(s) </TD>" &_
"<TD align='right' style='border-Top-style: solid'><font face='Tahoma' size='2'>" & strTotalCount & " file(s)" & "</TD>" &_
"<TD align='right' style='border-Top-style: solid'><font face='Tahoma' size='2'>" & strTotalSize & " KB" & "</TD></TR></Table>")
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
-------------------------------------------------------
Any suggestions?
Cheers!
ÙÇãá
It's important to learn the rules so that you know how to break them.