Solved

Check files DateLastModified only in First Level SubFolders

Posted on 2009-07-16
2
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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