Solved

Copy multiple files/multiple subdirectories to backup folder

Posted on 2003-12-04
6
695 Views
Last Modified: 2008-03-10
Hi,

I'm trying to write a script to backup our databases, when run. Each of our databases consists of 12 indivdual files, and there are about 100 databases, stored in different subdirectories. I'm trying to simply make copies of these files into a specified directory, then I can burn the contents to CD-ROM.

This is the (non functioning) script that I've got so far....

Dim FSO, FolderRoot, FolderList, FolderName, Listing, SubFolder, FolderPath
Dim ACF, BTX, INI, TBA, DBO, DBR, DBS, IXL, OCC, SDO, SLT, LOG
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FolderRoot = FSO.GetFolder("Q:\Textbase\")
Set FolderList = FolderRoot.SubFolders

For Each FolderName in FolderList
      Listing = Listing & FolderName.name
      FolderPath = "Q:\Textbase\"&Listing
      ACF = FolderPath&"\*.acf"
      BTX = FolderPath&"\*.btx"
      INI = FolderPath&"\*.ini"
      TBA = FolderPath&"\*.tba"
      DBO = FolderPath&"\*.dbo"
      DBR = FolderPath&"\*.dbr"
      DBS = FolderPath&"\*.dbs"
      IXL = FolderPath&"\*.ixl"
      OCC = FolderPath&"\*.occ"
      SDO = FolderPath&"\*.sdo"
      SLT = FolderPath&"\*.slt"
      LOG = FolderPath&"\*.log"
      'MsgBox ACF & vbCrLF & BTX & vbCrLF & INI & vbCrLF & TBA & vbCrLF & DBO & vbCrLF & DBR & vbCrLF & DBS & vbCrLF & IXL & vbCrLF & OCC & vbCrLF & SDO & vbCrLF & LOG & vbCrLF & SLT, VBOKOnly, "DB/TextWorks Backup System"
            If FSO.FileExists(ACF) Then
                  FSO.CopyFile ACF,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile BTX,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile INI,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile TBA,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile DBO,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile DBR,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile DBS,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile IXL,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile OCC,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile SDO,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile SLT,"Q:\Textbase\!CD Burning"
                  FSO.CopyFile LOG,"Q:\Textbase\!CD Burning"
            End If
      Listing = ""
Next

MsgBox "Backup Complete", VBOKOnly, "DB/TextWorks Backup System"

Set FSO = Nothing
0
Comment
Question by:ije
[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
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9878776
Have you considered just using plain old xcopy in a batch file?

Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.
0
 
LVL 6

Author Comment

by:ije
ID: 9879067
Thanks Idle_Mind, but I really need something I can setup for less techincal people to use (I'm going to stick a shortcut in their menu, give a nice Windows MsgBox at the end). If it looks like DOS, or requires DOS input, they'll freak..... :(

Also, I don't want to retain the folder structure - I just want to be able to trawl through all of the subdirectories of "Q:\Textbase" and dump all of the specified 12 formats into the "Q:\!CD Backup" folder.

Thanks for your input through - I haven't even thought about using batch files for years!!! :)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9879553
I can write it in VB but have had only limited experience with script.  Are you set on only using script?

Idle_Mind
0
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!

 
LVL 6

Author Comment

by:ije
ID: 9881630
Yes, def. need in VBScript - will eventually be ties into a seperate document logging script I have....
0
 
LVL 5

Accepted Solution

by:
mccainz2 earned 125 total points
ID: 9884448
All files, including nested subdirectories and their files, will be removed from disk with this program.


Sub Command1_Click()
  Dim TempDir As String
  TempDir = "C:\TEST"
  Nuke TempDir
End Sub

Sub Nuke(DirName As String)
  Const ATTR_NORMAL = 0
  Const ATTR_DIRECTORY = 16

  Dim OriginalDir, FileName, NextFileName As String

  OriginalDir = CurDir$
  ChDir DirName
  FileName = Dir$("*.*", ATTR_NORMAL)
  Do While FileName <> ""
      Kill FileName
      FileName = Dir$
  Loop

  Do
    FileName = Dir$("*.*", ATTR_DIRECTORY)
    While FileName = "." Or FileName = ".."
    FileName = Dir$
  Wend

    If FileName = "" Then Exit Do
    Nuke (FileName)
  Loop    

  ChDir OriginalDir
  RmDir DirName
End Sub

0
 
LVL 29

Expert Comment

by:leonstryker
ID: 10267572
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered mccainz2
 
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

leonstryker
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

710 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