Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check files DateLastModified only in First Level SubFolders

Posted on 2009-07-16
2
Medium Priority
?
519 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

773 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