Advertisement

11.29.2006 at 02:21PM PST, ID: 22077063
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Problem with script

Asked by iptrader in Visual Basic Programming

I initially wrote a script that returns # of files, folders and folder size in a specific folder based on an input directory.  I am trying to modify the script to read from a source file, and it is not working.  Additionally, on directories with less than 100KB, it is not returning size.  Can someone help me de-bug it please?  Code is below.

Thanks,

IPT

*******************

Option Explicit
On Error Resume Next

Dim objfso, boolExcel, objXL, cellcount, nTotal, FolderCount, drive, fso, fl, folder, fsize, TotalSize, openfile, fstring_err

set objfso = createobject("scripting.filesystemobject")

if objfso.FileExists("C:\Program Files\Microsoft Office\Office11\excel.exe") then
      boolExcel = true
      Set objXL = WScript.CreateObject("Excel.Application")
end if

if boolExcel then
      objXL.Visible = TRUE
      objXL.WorkBooks.Add

      objXL.Columns(1).ColumnWidth = 30
      objXL.Columns(2).ColumnWidth = 30
      objXL.Columns(3).ColumnWidth = 30
      objXL.Columns(4).ColumnWidth = 30
      
      objXL.Cells(1, 1).Value = "Folder Name"
      objXL.Cells(1, 2).Value = "Number of Files"
      objXL.Cells(1, 3).Value = "Number of Folders"
      objXL.Cells(1, 4).Value = "Size of Root Folder"

      cellcount = 4
else
      set output = objfso.CreateTextFile("filecheck.txt",true)
      output.writeline "Folder Name,File Count,Size"
end if

Set fso = CreateObject("Scripting.FileSystemObject")
Set fstring_err = fso.CreateTextFile("c:\errorlog.txt", True)
Set getfilepath = fso.GetFile("c:\checkfilesize.txt")
Set openfile = getfilepath.OpenAsTextStream(1, -2)
        Do While Not openfile.AtEndOfStream
                  strfilepath = ""
                  strfilepath = openfile.ReadLine
                              For Each strfilepath in getfilepath
                                    Set fl = fso.GetFolder(strfilepath)                        
                                          GetFileCount fl
                                          objXL.Cells(cellcount,1) = fl.path
                                          objXL.Cells(cellcount,2) = nTotal
                                          objXL.Cells(cellcount,3) = FolderCount
                                          objXL.Cells(cellcount,4) = fsize
                                          cellcount = cellcount + 1
                              Next
        Loop
            msgbox "Process completed!"
      
openfile.Close
fstring_err.Close
Set fso = Nothing
Set wsh = Nothing

Function GetFileCount(fl)
Dim nextFolder, folders, Files, SubFolders, SubFolder, firstpass, nextf
err.clear
nextFolder = fl.Path
Set Files = fl.Files
Set folders = fl.subfolders
nTotal = nTotal + Files.Count
FolderCount = FolderCount + folders.Count
Set SubFolders = fl.SubFolders
For Each SubFolder In SubFolders
      nextf = nextf & folders.Count
    nextFolder = nextFolder & GetFileCount(SubFolder)
            fsize = round(fl.size /1024)
            if len(fsize) >= 4 then
                  fsize = Round(fsize /1024) & " MB"
            else
                  fsize = Round(fsize) & " KB"
            end if      
      if err.number <> 0 then
            msgBox SubFolder & " - " & err.description
      end if            
Next
End Function Start Free Trial
 
Loading Advertisement...
 
[+][-]11.29.2006 at 02:59PM PST, ID: 18041436

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Sign Up Now!
Solution Provided By: jkaios
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11.29.2006 at 03:11PM PST, ID: 18041520

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32