Announcement

Collapse
No announcement yet.

List Folder path created between dates

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • List Folder path created between dates

    Hello,

    My objective is to have a .csv/.xls file with folder paths of folders that were created between a range of dates.
    (The folders UNC is in hebrew, if that matters)

    Anyway, can you refer me to a program or a procedure that do it, or i dont know help me write a script that does this thing.

    Thank you so much for any insight,

    Mike.

  • #2
    Re: List Folder path created between dates

    Originally posted by Badamin33 View Post
    My objective is to have a .csv/.xls file with folder paths of folders that were created between a range of dates.
    (The folders UNC is in hebrew, if that matters)
    WMI to the rescue! You can use WMI to get all kinds of information from the system, and files & directories are no exception.

    This example will list names and creation dates for all the directories on mapped network drive N: that were created after 2009-01-01. Just tune the query to get desired results.

    For the hebrew part, I have no idea if causes any problems. Just be careful and check in which format you specify the dates. Most of the world uses (the US being a notorious exception) either YYYY-MM-DD or DD-MM-YYYY, in which the most significant bit is either on the leftmost or the rightmost - never in between. This makes it easy to sort and compare dates.

    (You might want to take a look on The Turkey Test, which deals about some suprises developers might encounter:
    http://www.moserware.com/2008/02/doe...rkey-test.html )

    Some info about available Win32_Directory properties is at MSDN: http://msdn.microsoft.com/en-us/libr...30(VS.85).aspx

    Code:
    strComputer = "."
     
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
    Set colFolders = objWMIService.ExecQuery("Select * from " _
    & "Win32_Directory where drive='n:' and CreationDate > '20090101'")
     
    For Each objFolder in colFolders
    Wscript.Echo objFolder.Name & " " & objFolder.CreationDate
    Next
    -vP

    Comment


    • #3
      Re: List Folder path created between dates

      Originally posted by vonPryz View Post
      WMI to the rescue! You can use WMI to get all kinds of information from the system, and files & directories are no exception.

      This example will list names and creation dates for all the directories on mapped network drive N: that were created after 2009-01-01. Just tune the query to get desired results.

      For the hebrew part, I have no idea if causes any problems. Just be careful and check in which format you specify the dates. Most of the world uses (the US being a notorious exception) either YYYY-MM-DD or DD-MM-YYYY, in which the most significant bit is either on the leftmost or the rightmost - never in between. This makes it easy to sort and compare dates.

      (You might want to take a look on The Turkey Test, which deals about some suprises developers might encounter:
      http://www.moserware.com/2008/02/doe...rkey-test.html )

      Some info about available Win32_Directory properties is at MSDN: http://msdn.microsoft.com/en-us/libr...30(VS.85).aspx

      Code:
      strComputer = "."
       
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
       
      Set colFolders = objWMIService.ExecQuery("Select * from " _
      & "Win32_Directory where drive='n:' and CreationDate > '20090101'")
       
      For Each objFolder in colFolders
      Wscript.Echo objFolder.Name & " " & objFolder.CreationDate
      Next
      -vP
      Hello,

      Thank you so much for this.
      but how do i make it export to a csv in colums ?
      so for example colum A will be the path and colum B will be the date CREATED ?

      I would really appreciate your help with this

      thank you

      Comment


      • #4
        Re: List Folder path created between dates

        To write to a csv-file,
        Code:
        ' Drive or share to start from:
        strStart = "\\server1\sharename"
        
        ' Folder creation date between:
        dateGEQ = 20090101   ' greater than or equal yyyymmdd
        ' and
        dateLEQ = 20090101   ' less than or equal yyyymmdd
        
        ' Write to CSV file:
        outFile = "c:\test\Foldersfnd.csv"
        
        Dim fso : Set fso = WScript.CreateObject("Scripting.FileSystemObject")
        
        If Left(strStart, 2) = "\\" Then
           strDrive = FreeDrive
        ElseIf Mid(strStart, 2, 1) = ":" Then
           strDrive = Left(strStart, 2)
        Else
           wsh.echo "end"
           wscript.quit
        End If
        
        strComputer = "."
        
        Set objNet = WScript.CreateObject("WScript.Network")
        objNet.MapNetworkDrive strDrive, strStart, False
        
        Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" _
          & strComputer & "\root\cimv2")
        
        Set colFolders = objWMIService.ExecQuery("Select * from " _
          & "Win32_Directory where drive = '" & strDrive _
          & "' and CreationDate >= '" & dateGEQ _
          & "' and CreationDate <= '" & dateLEQ & "'")
        
        Set objFile = fso.CreateTextFile(outFile, True)
        
        ' first line, write column titles
        objFile.WriteLine "Folder name,Creation date, Time"
        
        For Each objFolder in colFolders
           folderName = replace(lcase(objFolder.Name), _
              lCase(strDrive), lcase(strStart))
        
           dt = objFolder.CreationDate
           d = DateSerial(Mid(dt,1,4), mid(dt,5,2), mid(dt,7,2))
           t = TimeSerial(Mid(dt,9,2), mid(dt,11,2), mid(dt,13,2))
        
           objFile.WriteLine _
              """" & folderName & """," & d & "," & t & "," & objFolder.CreationDate
        Next
        
        objFile.Close
        objNet.RemoveNetworkDrive strDrive, true, true
        
        wsh.echo "done"
        
        
        Function FreeDrive
          With fso
           For i = Asc("D") To Asc("Z") 
              If Not .DriveExists(Chr(i)) Then 
                 FreeDrive = Chr(i) & ":" 
                 Exit For 
              End If 
           Next
          End With
        End Function
        \Rems
        Last edited by Rems; 18th February 2009, 11:03.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: List Folder path created between dates

          thank you so much !

          Comment

          Working...
          X