Solved

Copy multiple files/multiple subdirectories to backup folder

Posted on 2003-12-04
6
691 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
6 Comments
 
LVL 85

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 85

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
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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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