locked
How to Total The Size for Files created on Certain Date? RRS feed

  • Question

  • Hi all,
    I know how to list them but I want to know the total size of all files created on certain date.
    Can anyone help?

    Thanks,
    SB
    Thursday, August 13, 2009 9:02 AM

Answers

  • Hi SB,

    This script will add up the file size of all files under the userdata folder created on 7/8/2009:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colFiles = objWMIService. _
        ExecQuery("Select * from CIM_DataFile where Path = '\\userdata\\'")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    x = 0
    For Each objFile in colFiles
        Set objFile1=objFSO.GetFile(objFile.Name)
        If Instr(objFile1.DateCreated,"7/8/2009") then
           Wscript.Echo objFile.Name, objFile1.DateCreated, objFile1.Size
           x = x + objFile1.Size
        End if
    Next
    Wscript.Echo "Total size of files created on 7/8/2009 : " & x
    Regards,

    Salvador Manaois III
    MCITP | Enterprise & Server Administrator
    MCSE MCSA MCTS(x5) CIWA C|EH
    My Blog: Bytes and Badz 
    My Shots: View My PhotoStream
    Thursday, August 13, 2009 10:38 AM
  • Pretty table with date, size, and count. In PowerShell:

    Dir | group {$_.CreationTime.date} | 
    format-table Name, @{label="TotalSize"; expression= {($_.group | Measure-Object length -sum).sum}}, count, group -autosize

    Will show something like this as result:

    Name               TotalSize Count Group
    ----               --------- ----- -----
    11.08.2009 0:00:00  10093624    11 {fw301v12r6.zip, GoodNews.msi...}
    12.08.2009 0:00:00  57139634     5 {209886.zip, 425756.zip, 430281.zip...}
    24.07.2009 0:00:00    151236     3 {ARJ.EXE, script.ps1, upload.txt}
    02.07.2009 0:00:00   2466618     2 {spamfighter_web.exe, spamfighter_web.zip}

    AKA Xaegr, MCSE: Security, Messaging; MCITP: Server\Enterprise Administrator; Блог: http://xaegr.wordpress.com
    Thursday, August 13, 2009 7:53 PM

All replies

  • Hi SB,

    This script will add up the file size of all files under the userdata folder created on 7/8/2009:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colFiles = objWMIService. _
        ExecQuery("Select * from CIM_DataFile where Path = '\\userdata\\'")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    x = 0
    For Each objFile in colFiles
        Set objFile1=objFSO.GetFile(objFile.Name)
        If Instr(objFile1.DateCreated,"7/8/2009") then
           Wscript.Echo objFile.Name, objFile1.DateCreated, objFile1.Size
           x = x + objFile1.Size
        End if
    Next
    Wscript.Echo "Total size of files created on 7/8/2009 : " & x
    Regards,

    Salvador Manaois III
    MCITP | Enterprise & Server Administrator
    MCSE MCSA MCTS(x5) CIWA C|EH
    My Blog: Bytes and Badz 
    My Shots: View My PhotoStream
    Thursday, August 13, 2009 10:38 AM
  • Pretty table with date, size, and count. In PowerShell:

    Dir | group {$_.CreationTime.date} | 
    format-table Name, @{label="TotalSize"; expression= {($_.group | Measure-Object length -sum).sum}}, count, group -autosize

    Will show something like this as result:

    Name               TotalSize Count Group
    ----               --------- ----- -----
    11.08.2009 0:00:00  10093624    11 {fw301v12r6.zip, GoodNews.msi...}
    12.08.2009 0:00:00  57139634     5 {209886.zip, 425756.zip, 430281.zip...}
    24.07.2009 0:00:00    151236     3 {ARJ.EXE, script.ps1, upload.txt}
    02.07.2009 0:00:00   2466618     2 {spamfighter_web.exe, spamfighter_web.zip}

    AKA Xaegr, MCSE: Security, Messaging; MCITP: Server\Enterprise Administrator; Блог: http://xaegr.wordpress.com
    Thursday, August 13, 2009 7:53 PM
  • Can this be done for a date range?

    For example I need to export, to open in Excel, the date created and total file size for all files in a particulare folder, actually it would be great if i could traverse folders 1 level, for all files created in 2009, is that possible?

    Thanks,

    Wednesday, March 2, 2011 5:06 PM
  • Personally, I see no reason to involve WMI in this.  Here is how I would do it in VBS (I don't do PS)  ...

    sPath = "." ' default to current folder - change to match desired location
    if wsh.arguments.count > 0 then sPath = wsh.arguments(0)
    sSearchYear = "2009"
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    if oFSO.FolderExists(sPath) then
       set oFolder = oFSO.GetFolder(sPath)
       nSize = GetSize(oFolder, sSearchYear, false)
      For each subFolder in oFolder.Subfolders
        nSize = nSize + GetSize(subFolder, sSearchYear, false)
      Next

      wsh.Echo "Total size of files created in " & sSearchYear & ": " & nSize\1024 & " KB"
    end if

    Function GetSize(oFolder, sSearchYear, bVerbose)
    Dim x, oFile

      For Each oFile in oFolder.Files
        If cstr(year(oFile.DateCreated)) = cstr(sSearchYear) then
           if bVerbose then wsh.Echo oFile.Name, oFile.DateCreated, oFile.Size
           x = x + oFile.Size
        End if
      Next

      GetSize = x

    end Function


    Tom Lavedas
    Wednesday, March 2, 2011 6:14 PM
  • Personally, I see no reason to involve WMI in this.  Here is how I would do it in VBS (I don't do PS)  ...

    I would go one step further: Since WMI takes about 40 times longer to do the same job as the equivalent VB Script, I avoid it whenever I can.
    Wednesday, March 2, 2011 7:19 PM