Solved

automating folder moves via VBScript by age

Posted on 2008-10-21
1
589 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
[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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

617 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