Solved

Check files DateLastModified only in First Level SubFolders

Posted on 2009-07-16
2
514 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:usdcaz
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 24873059
This should do it.


strSource = "W:\CasesT"
strDest = "W:\Cases2"
intMonths = 1
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strSource)
 
For Each objSubfolder in objFolder.SubFolders
    For Each objFile in objSubfolder.Files
        dtmDate = objFile.DateLastModified
        
        If DateDiff("m", dtmDate, Date) < intMonths Then
            objFSO.CopyFolder objSubfolder.Path, strDest & "\"
            Exit For
        End If
    Next
Next

Open in new window

0
 

Author Closing Comment

by:usdcaz
ID: 31604365
Great, worked perfectly! Thanks you for your help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question