Link to home
Start Free TrialLog in
Avatar of Intelli-Seeker
Intelli-SeekerFlag for United States of America

asked on

Add date modified to script to get folder details

I had this question after viewing Script to get folder details.

This script is awesome! The only items that I would like to add are the date modified and the date created. Can someone assist with that? I have attached the original file.

' Set up filesystem object for usage
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Get folder name to list off the command line, make sure it's valid
If (WScript.Arguments.Count > 0) Then
    strFolder = Wscript.Arguments(0)
    If Not objFSO.FolderExists(strFolder) Then
        WScript.StdErr.WriteLine "Specified folder does not exist."
        WScript.Quit
    End If
Else
    WScript.StdErr.WriteLine "No folder name specified to list."
    WScript.Quit
End If

' Look for files
DoFolder objFSO.GetFolder(strFolder)

Sub DoFolder(objFolder)
   On Error Resume Next

   If Err.Number = 0 Then
      ' Parent folder
      PrintFolderLine objFolder.Path
'      PrintFolderLine(objFolder.Path) & "," & objFolder.Files.Count & "," & objFolder.SubFolders.Count & "," & objFolder.Size

      PrintHeader

      ' List all folders first
      For Each objSubFolder In objFolder.SubFolders
         On Error Resume Next
         PrintDirLine objSubFolder.Name, FormatSize(objSubFolder.Size), objSubFolder.SubFolders.Count, objSubFolder.Files.Count
         If Err.Number <> 0 Then 
            PrintDirLine objSubFolder.Name, "N/A", "N/A""N/A", "N/A"
         End If
         On Error Goto 0
      Next

      ' List files
      For Each objFile In objFolder.Files
         PrintFileLine objFile.Name, FormatSize(objFile.Size)
      Next

      ' Recursively drill down into subfolder
      For Each objSubFolder In objFolder.SubFolders
         On Error Resume Next
         DoFolder objSubFolder
      Next
   Else
      PrintFolderLine "N/A"
   End If

   On Error Goto 0

End Sub

Sub PrintHeader()
   Wscript.Echo LPad("SUBFOLDERS", 12, " ") & " " & LPad("FILES", 12, " ") & " " & LPad("SIZE", 12, " ") & "  " & "FILENAME"
   Wscript.Echo String(12, "-") & " " & String(12, "-") & " " & String(12, "-") & "  " & String(40, "-")
End Sub

Sub PrintFileLine(strName, strSize)
   Wscript.Echo String(12, " ") & " " & String(12, " ") & " " & LPad(strSize, 12, " ") & "  " & strName
End Sub

Sub PrintDirLine(strName, strSize, strFolders, strFiles)
   Wscript.Echo LPad(strFolders, 12, " ") & " " & LPad(strFiles, 12, " ") & " " & LPad(strSize, 12, " ") & " *" & strName
End Sub

Sub PrintFolderLine(strFolder)
   Wscript.Echo vbNewLine & "Listing contents of " & strFolder & vbNewLine
End Sub

' Function to format a number into typical size scales
Function FormatSize(intSize)
   arrLabel = Array("  ", "KB", "MB", "GB", "TB")
   For i = 0 to 4
      If intSize > 1024 Then 
         intSize = intSize / 1024
      Else
         Exit For 
      End If
   Next
   FormatSize = Round(intSize, 2) & " " & arrLabel(i)
End Function

' Add surrounding double quotes to a string
Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

' Right pad a string to any length with a specified character
Function RPad(strText, intLen, chrPad)
  RPad = Left(strText & String(intLen, chrPad), intLen)
End Function

' Left pad a string to any length with a specified character
Function LPad(strText, intLen, chrPad)
  LPad = Right(String(intLen, chrPad) & strText, intLen)
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Intelli-Seeker

ASKER

That is exactly what I was looking for. Now I just need to dump it into Excel and am good to go.
Avatar of Bill Prew
Bill Prew

So, all set?

~bp
Yes Bill. It worked perfectly. Thanks!
Can you go ahead and close this question now that you have a solution and select the proper answer(s) please.

http://support.experts-exchange.com/customer/portal/articles/1089414

~bp
This was an excellent addition to the script. Thanks for your help. It is exactly what I needed.