Solved

Copy multiple files/multiple subdirectories to backup folder

Posted on 2003-12-04
6
684 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
Comment Utility
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
Comment Utility
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
Comment Utility
I can write it in VB but have had only limited experience with script.  Are you set on only using script?

Idle_Mind
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 6

Author Comment

by:ije
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now