CreateProcess & xcopy!!! 
Author Message
 CreateProcess & xcopy!!!

ARGH!!!

I want to launch an xcopy from my VB app.  I am trying to use
CreateProcess, but cannot figure out what is wrong.  I put "notepad" in
place of "xcopy" and no problem.  I've tried other things to, but
nothing I do gets xcopy to work.  I wanted to use CreateProcess because
I have code for it that will allow me to wait until the xcopy is
complete.  I can use "shell" to launch xcopy and that works, but I do
not remeber how to delay until the shelled process is complete.

Please help & MANY thanks,

Mike



Fri, 10 Aug 2001 03:00:00 GMT  
 CreateProcess & xcopy!!!
Why use xcopy? There are a zillion ways to copy a file that do not involve
shelling to a console.

Michael


Quote:
> ARGH!!!

> I want to launch an xcopy from my VB app.  I am trying to use
> CreateProcess, but cannot figure out what is wrong.  I put "notepad" in
> place of "xcopy" and no problem.  I've tried other things to, but
> nothing I do gets xcopy to work.  I wanted to use CreateProcess because
> I have code for it that will allow me to wait until the xcopy is
> complete.  I can use "shell" to launch xcopy and that works, but I do
> not remeber how to delay until the shelled process is complete.

> Please help & MANY thanks,

> Mike



Fri, 10 Aug 2001 03:00:00 GMT  
 CreateProcess & xcopy!!!
I want to copy a directory structure, updating files only if they are newer,
and creating the target directories if they do not exist.  xcopy does that all
for me in one command.  If there is a better way, I'm all ears.

Thanks,

Mike

Quote:

> Why use xcopy? There are a zillion ways to copy a file that do not involve
> shelling to a console.

> Michael



> > ARGH!!!

> > I want to launch an xcopy from my VB app.  I am trying to use
> > CreateProcess, but cannot figure out what is wrong.  I put "notepad" in
> > place of "xcopy" and no problem.  I've tried other things to, but
> > nothing I do gets xcopy to work.  I wanted to use CreateProcess because
> > I have code for it that will allow me to wait until the xcopy is
> > complete.  I can use "shell" to launch xcopy and that works, but I do
> > not remeber how to delay until the shelled process is complete.

> > Please help & MANY thanks,

> > Mike



Sat, 11 Aug 2001 03:00:00 GMT  
 CreateProcess & xcopy!!!
Of course there's a better way.  This example of the CopyFile api lets you
copy a file or a directory structure (Folder).  This is taken from Randy
Birch's VBNet Web page, which has solved more problems for me than I can
count (Thanks Randy).  If you want to visit his page directly, try
http://www.mvps.org/vbnet/

Bob Mergner
Healthworks Alliance, Inc.

Paste the following declarations:

Option Explicit  Public Const INVALID_HANDLE_VALUE = -1
  Public Const MAX_PATH = 260  Type FILETIME     dwLowDateTime As Long
     dwHighDateTime As Long  End Type  Type WIN32_FIND_DATA
     dwFileAttributes As Long     ftCreationTime As FILETIME
     ftLastAccessTime As FILETIME     ftLastWriteTime As FILETIME
     nFileSizeHigh As Long     nFileSizeLow As Long     dwReserved0 As Long
     dwReserved1 As Long     cFileName As String * MAX_PATH
     cAlternate As String * 14  End Type  Type SECURITY_ATTRIBUTES
     nLength As Long     lpSecurityDescriptor As Long     bInheritHandle As
Long
  End Type
  Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" _
      (ByVal lpPathName As String, _
       lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
  Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
      (ByVal lpExistingFileName As String, _
       ByVal lpNewFileName As String, _
       ByVal bFailIfExists As Long) As Long
  Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
      (ByVal lpFileName As String, _
      lpFindFileData As WIN32_FIND_DATA) As Long
  Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
      (ByVal hFindFile As Long, _
       lpFindFileData As WIN32_FIND_DATA) As Long
  Declare Function FindClose Lib "kernel32" _
      (ByVal hFindFile As Long) As Long

The use the following form and function:

Private Sub cmdCopyFiles_Click()   Dim sSourcePath As String
   Dim sDestination As String   Dim sFiles As String   Dim numCopied As Long
       'set the appropriate initializing values     sSourcePath = "c:\win\"
   sDestination = "c:\temptest\"   sFiles = "*.txt"
  'perform the copy and return the copied file count
   numCopied = rgbCopyFiles(sSourcePath, sDestination, sFiles)
   MsgBox numCopied & " files copied to " & sDestinationEnd Sub
Private Sub cmdEnd_Click()   Unload Me   End   End Sub
Public Function rgbCopyFiles(sSourcePath As String, _
                             sDestination As String, _
                             sFiles As String) As Long
   Dim WFD As WIN32_FIND_DATA   Dim SA As SECURITY_ATTRIBUTES      Dim r As
Long
   Dim hFile As Long   Dim bNext As Long   Dim copied As Long
   Dim currFile As String
  'Create the target directory if it doesn't exist
   Call CreateDirectory(sDestination, SA)
  'Start searching for files in the Target directory.
   hFile = FindFirstFile(sSourcePath & sFiles, WFD)
   If (hFile = INVALID_HANDLE_VALUE) Then
      'nothing to do, so bail out
       MsgBox "No " & sFiles & " files found."       Exit Function    End If
       'Copy each file to the new directory   If hFile Then            Do
                'trim trailing nulls, leaving one to terminate the string
         currFile = Left$(WFD.cFileName, InStr(WFD.cFileName, Chr$(0)))

        'copy the file to the destination directory & increment the count
         Call CopyFile(sSourcePath & currFile, sDestination & currFile,
False)
         copied = copied + 1                   'just to check what's
happening
         List1.AddItem sSourcePath & currFile
        'find the next file matching the initial file spec
         bNext = FindNextFile(hFile, WFD)
      Loop Until bNext = 0         End If       'Close the search handle
   Call FindClose(hFile)       'and return the number of files copied
   rgbCopyFiles = copied   End Function

Quote:

>I want to copy a directory structure, updating files only if they are
newer,
>and creating the target directories if they do not exist.  xcopy does that
all
>for me in one command.  If there is a better way, I'm all ears.

>Thanks,

>Mike


>> Why use xcopy? There are a zillion ways to copy a file that do not
involve
>> shelling to a console.

>> Michael



>> > ARGH!!!

>> > I want to launch an xcopy from my VB app.  I am trying to use
>> > CreateProcess, but cannot figure out what is wrong.  I put "notepad" in
>> > place of "xcopy" and no problem.  I've tried other things to, but
>> > nothing I do gets xcopy to work.  I wanted to use CreateProcess because
>> > I have code for it that will allow me to wait until the xcopy is
>> > complete.  I can use "shell" to launch xcopy and that works, but I do
>> > not remeber how to delay until the shelled process is complete.

>> > Please help & MANY thanks,

>> > Mike



Sun, 12 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Difference between VB CreateProcess / Shell & DOS session

2. CreateProcess & Window State

3. Help with CreateProcess & WaitForSingleObject

4. CreateProcess & WaitForSingleObject

5. *&*&*&* Date math question *&*&*&*

6. XCOPY

7. xcopy equivalent in vbscript

8. Xcopy Question

9. Q in regards to xcopy equivalent procedures in vb

10. Q in regards to xcopy equivalent procedures in vb

11. XCOPY IN VB

12. Need recursive copy routine (Like XCopy)

 

 
Powered by phpBB® Forum Software