Solved

Directory Copying

Posted on 1998-08-20
6
220 Views
Last Modified: 2010-04-30
What is the *simplest* way to copy an entire directory structure (and its files) from one drive to another?
0
Comment
Question by:IsleOfView
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1430076
SHELL("XCOPY " & dirspec & " " & target & " /S /E ", 1)

0
 

Author Comment

by:IsleOfView
ID: 1430077
Maybe I was a little too blunt with the "Simplest" comment.  I want to have this accomplished in VB.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1430078
SHELL command *IS* VB. No shame in using existing machine resource.

Are you coding for fun or $$$?

If you're coding in *MY* shop for $$$ then this is simplest, most reliable solution. Least cost to implement, little to debug. This produces the desired result, no? So why is not "correct" answer. No need to re-invent the wheel.

If you're coding for fun, then by all means, write a couple of pages of code.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:IsleOfView
ID: 1430079
How can I make VB wait for the shell command to finish execution?  (and close the DOS window).  I would prefer this to happen from within VB, as this is going to a large customer base and the thought is that it would be more professional without DOS windows popping up all over the place...
0
 

Author Comment

by:IsleOfView
ID: 1430080
I really need this to work through the API.
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 100 total points
ID: 1430081
Ahhh, making VB wait for a child task to complete requires some code but does work well. This was lifted wholesale from the M$ web site:

'
' These data type declarations are required to support the obscure windows
' function to spawn a child task and wait for it to finish before continuing
'
Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type
'
Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type
'
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) As Long
'
Private Declare Function CreateProcessA Lib "kernel32" ( _
    ByVal lpApplicationName As Long, _
    ByVal lpCommandLine As String, _
    ByVal lpProcessAttributes As Long, _
    ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, _
    ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, _
    ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, _
    lpProcessInformation As PROCESS_INFORMATION) As Long
'
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'
Const NORMAL_PRIORITY_CLASS = &H20&
Const INFINITE = -1&
'
' I don't really understand the above declares, but they do work so DON'T MESS WITH THEM!
'
'
Public Sub ExecCmd(cmdline$)
'
' This executes an external windows program and waits for it to complete
'
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'
' Initialize the STARTUPINFO structure:
'
start.cb = Len(start)
'
' Start the shelled application
'
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'
' Wait for the shelled application to finish:
'
holdhere:
    DoEvents
    ret& = WaitForSingleObject(proc.hProcess, 5000)
    If ret& <> 0 Then GoTo holdhere
'
ret& = CloseHandle(proc.hProcess)
End Sub

Call the above with:

ExecCmd cmdstring

Where CMDSTRING is "XCOPY " & dirspec & " " & target & " /S /E "
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA loop through headers using value 3 56
VBA Excel: Copy Data from one workbook to another v7 new parameter to by pass prefix name 2 50
using Access 8 58
Copy a row 12 57
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

914 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

21 Experts available now in Live!

Get 1:1 Help Now