Solved

automating folder moves via VBScript by age

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

12 Experts available now in Live!

Get 1:1 Help Now