TimH said:
Thanks Nikos,
The purpose of the database is to create a bootable backup (clone) of a
primary HDD onto a redundant backup HDD. In this case, we need to copy system
files, hidden files, and to create folders if they do not exist. I would
normally ghost the HDD, however, the daily operator of the system is not very
computer literate, and needs an "icon" to do the job. Will the script that
you kindly included in your reply, capture all files and folders, creating a
clone?
Hmm... no, I'm afraid it won't. This will only copy all files within a
given folder, I hadn't realized what you were trying to accomplish.
I spent some time on it just for kicks, and came up with this:
Sub copy_folder()
Dim fs, f, src, dest, vFile
Dim vFsrc, vFdest, strHidden, arrHidden
Dim strSystem, arrSystem
src = "C:\"
dest = "D:\"
Set fs = CreateObject("Scripting.FileSystemObject")
' Unset Hidden and System attribute in destination folder
On Error GoTo folder_does_not_exist
Set f = fs.getfolder(dest)
On Error GoTo 0
For Each vFile In f.files
SetAttr (vFile), vbNormal
Next
folder_does_not_exist:
On Error GoTo 0
' Unset Hidden and System attribute
Set f = fs.getfolder(src)
For Each vFile In f.files
vAttr = GetAttr(vFile)
If vAttr And vbHidden Then
strHidden = strHidden & vFile.Name & ";"
SetAttr vFile, vAttr - vbHidden
End If
vAttr = GetAttr(vFile)
If vAttr And vbSystem Then
strSystem = strSystem & vFile.Name & ";"
SetAttr vFile, vAttr - vbSystem
End If
Next
' Copy folder
f.Copy Left(dest, Len(dest) - 1), True
' Re-set Hidden attribute
If Len(strHidden) > 0 Then
strHidden = Left(strHidden, Len(strHidden) - 1)
arrHidden = Split(strHidden, ";")
For i = 0 To UBound(arrHidden)
vFsrc = src & arrHidden(i)
vFdest = dest & arrHidden(i)
SetAttr vFsrc, GetAttr(vFsrc) + vbHidden
SetAttr vFdest, GetAttr(vFdest) + vbHidden
Next
End If
' Re-set System attribute
If Len(strSystem) > 0 Then
strSystem = Left(strSystem, Len(strSystem) - 1)
arrSystem = Split(strSystem, ";")
For i = 0 To UBound(arrSystem)
vFsrc = src & arrSystem(i)
vFdest = dest & arrSystem(i)
SetAttr vFsrc, GetAttr(vFsrc) + vbSystem
SetAttr vFdest, GetAttr(vFdest) + vbSystem
Next
End If
End Sub
which (sort of) replicates the functionality of XCOPY and might do the
job just fine; though I haven't tested it to copy a whole HDD partition
as above (it would take forever), it has proven to work fine for
folders. I trust it would do the job, given enough time.
The catch: the Copy method won't work with hidden or system files, so I
reset them before the copy, and rsstore their previous status
afterwards. The problem is this is done in the root directory only. In
theory, you could put the code snippets that do that in separate subs,
and call them as many times as required for different folders, provided
those are stored somewhere... but this is going too far! if the aim is
to backup an entire HDD including system files, then Access is not the
wy to do it! There are special tools for that, and there's one readily
available that ships with Windows and is already in your system... or
you could use a plain DiskCopy in a DOS window.
Regards,
Nikos