Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy multiple files/multiple subdirectories to backup folder

Posted on 2003-12-04
6
Medium Priority
?
700 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

824 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