Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive Folder Loop and Date Constraint

Status
Not open for further replies.

albitzt

Technical User
Sep 8, 2010
13
US
Hi All,

First off let me say thanks in advance for taking a look. I have been messing around with the code below that I put together for a few different sources. I'm a Newbie, so knowledge is limited. The end goal is I need a script that sets a root folder and looks through *only folders) under the root. It needs to then compare the DateCreated to current date - xdays and if it meets the criteria output the obj DateCreated and Name to a file.

So the criteria is:
#1 - Loop to evaluate each subfolder under the root folder
#2 - Evaluate the DateCreated against current date - xdays
#3 - Output DateCreated/Name if it meets critera.

Any help would be appreciated. What I have so far is below:

Code:
'Set Root Folder to Search
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFolder("C:\testfolder")

'Open file for logging
Dim ObjFso1
Dim StrFileName
Dim ObjFile1
 StrFileName = "C:\output.log"
Set ObjFso1 = CreateObject("Scripting.FileSystemObject")

'Creating a file for writing data
Set ObjFile1 = ObjFso1.CreateTextFile(StrFileName)


Wscript.Echo "Date created: " & objFile.DateCreated
Wscript.Echo "Date last accessed: " & objFile.DateLastAccessed
Wscript.Echo "Date last modified: " & objFile.DateLastModified
Wscript.Echo "Drive: " & objFile.Drive
Wscript.Echo "Name: " & objFile.Name
Wscript.Echo "Parent folder: " & objFile.ParentFolder
Wscript.Echo "Path: " & objFile.Path
Wscript.Echo "Short name: " & objFile.ShortName
Wscript.Echo "Short path: " & objFile.ShortPath
Wscript.Echo "Size: " & objFile.Size
Wscript.Echo "Type: " & objFile.Type

ObjFile1.WriteLine(objFile.Name)
ObjFile1.WriteLine(objFile.DateCreated)
WScript.Quit

'Closing the file
ObjFile1.Close
 
Already a lot of threads and even faq in this site on such topic, so, please, use the search facilities.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Finally got this working...Posting in case this can save someone else some time....

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFile = FSO.CreateTextFile("C:\vb_output.log", True)
ShowSubfolders FSO.GetFolder("D:\backups")

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        Set objWMIService = GetObject("winmgmts:")
        Set objFolderSecuritySettings = _
           objWMIService.Get("Win32_LogicalFileSecuritySetting='" & Folder & "'")
    intRetVal = objFolderSecuritySettings.GetSecurityDescriptor(objSD)

    If intRetVal = 0 Then
                                If Subfolder.DateCreated < (Date - 14) Then
								Wscript.Echo "Name: " & SubFolder.Name
								Wscript.Echo "Date created: " & SubFolder.DateCreated
								'WScript.Echo "Owner: " & objSD.Owner.Domain & "\" & objSD.Owner.Name
								objFile.WriteLine "Name: " & SubFolder.Name
								objFile.WriteLine "Date created: " & SubFolder.DateCreated
								end if
                                                                                
end if
Next
'close file
objFile.Close
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top