Solved

Check files DateLastModified only in First Level SubFolders

Posted on 2009-07-16
2
512 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now