Solved

automating folder moves via VBScript by age

Posted on 2008-10-21
1
584 Views
Last Modified: 2013-11-10
I'm trying to automate the process of moving archived email folders off our mail server to a backup server based on age criteria.
I thought I had the whole thing working, but now the age requirement isn't working.

here's my code

OPTION EXPLICIT
dim oFS, oFolder, nfolder, count, count2, maxage, includesubfolders, oSubFolder, of, nf
of = "C:\Documents and Settings\user\Desktop\test"
nf = "C:\Documents and Settings\user\Desktop\test2"
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder(of)
set nFolder = oFS.GetFolder(nf)
set osubfolder = ofolder.subfolders

count = nfolder.subfolders.count
maxage = 1
includesubfolders = true
      for each osubfolder in ofolder.subfolders
      on error resume next
            IF oSubFolder.DateLastModified < (Now - MaxAge) THEN
            oFS.copyFolder of, nf

      
            count2 = nfolder.subfolders.count
                  if count2 > count then
                        oFS.deleteFolder of      
                        
                  end if      

            end if
      next
0
Comment
Question by:ddotson
1 Comment
 

Accepted Solution

by:
ddotson earned 0 total points
ID: 22771300
I think I found my own answer
if anyone has a better way to do this, great, if now I'll go with this.

OPTION EXPLICIT
dim oFS, oFolder, nfolder, count, count2, maxage, includesubfolders, oSubFolder, of, nf
of = "C:\Documents and Settings\user\Desktop\test\"
nf = "C:\Documents and Settings\user\Desktop\test2\"
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder(of)
set nFolder = oFS.GetFolder(nf)
set osubfolder = ofolder.subfolders

count = nfolder.subfolders.count
maxage = 1
includesubfolders = true

      for each osubfolder in ofolder.subfolders
      on error resume next
            IF oSubFolder.DateLastModified < (Now - MaxAge) THEN
                  oFS.copyFolder osubfolder, nf

                  count2 = nfolder.subfolders.count
                        if count2 > count then
                              On Error Resume Next
                              oFS.deleteFolder osubfolder
                                    
                        end if      

            
            end if
      next
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

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

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

22 Experts available now in Live!

Get 1:1 Help Now