Wait for application to complete

G

Guest

Hi,
I am writing a database that runs XCOPY to copy files to another drive using
RunApp
in a macro. I need to pause the macro until the files are copied and XCOPY
closes, or alternatively, write another macro which launches when XCOPY
completes.
Any ideas?
Thanks.
 
N

Nikos Yannacopoulos

Tim,

I don't think this can be done in a macro. It's probably time for you to
get into VB code, which will solve your problem. One way to start is to
convert your existing macro to a module, and then replace the RunApp
part of the code with:

vSource = "c:\somefolder\....\"
vDestination = "d:\someotherfolder\.....\
Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.GetFolder(vSource)
Set fls = fldr.Files
For Each fl In fls
FileCopy vSource & fl.Name, vDestination & fl.Name
Next fl

This will carry out the file copying from within Access, without the
need to open a DOS window... and, of course, execution will only proceed
further after the last file has been copied. What's more, you won't have
an issue when you - eventually - move to Win XP x64 (the 64-bit
edition), which will no longer support DOS mode!

HTH,
Nikos
 
G

Guest

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?
 
N

Nikos Yannacopoulos

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top