Link to home
Start Free TrialLog in
Avatar of usdcaz
usdcazFlag for United States of America

asked on

Check files DateLastModified only in First Level SubFolders

I am fairly new to vbscript, but learning every day. I need a vbscript that will check only in the first level subfolder from the root folder. Then it checks the DateLastModified on all files in that folder. If a file meets criteria, then copy (or preferably move) that folder (and its contents) to another folder. I have the following code, but it checks All Subfolders.
Set objFSO = CreateObject("Scripting.FileSystemObject")
objRootFolder = "W:\CasesT"
Set objFolder = objFSO.GetFolder(objRootFolder)
ShowSubfolders objFSO.GetFolder(objRootFolder)
Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        Set objFolder = objFSO.GetFolder(folder.Path)
        Set colFiles = objFolder.Files
  	a = 0
    For Each objFile in colFiles
	dtmDate = objFile.DateLastModified
	fileDate = DateDiff("m", dtmDate, Date)
	If fileDate < 1 Then
	a = 1
	Exit For
	End If
        Next
	If a = 1 Then
	objFSO.CopyFolder objFolder.Path , "W:\Cases2\"
	End If
        ShowSubFolders Subfolder
    Next
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

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 usdcaz

ASKER

Great, worked perfectly! Thanks you for your help!