Solved

automating folder moves via VBScript by age

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

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

In this post we will learn different types of Android Layout and some basics of an Android App.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

739 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