Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

automating folder moves via VBScript by age

Posted on 2008-10-21
1
Medium Priority
?
590 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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…
Starting up a Project

688 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