I am trying to copy the contents of a folder into another folder in another drive using XCOPY.

Here is code I have now but it isn't working and I figure xcopy would be the easier way to go because MOVETO and CopyDirectory haven't been working because its copying files to a different directory.

Sub CopyFiles()

        Dim DestinationDirectory As String = "I:\New\Export\ID"
        Dim SourceDirectory As String = "C:\Temp2\"


        Try
            Dim f() As String = Directory.GetFiles(SourceDirectory)
            For i As Integer = 0 To UBound(f)
                File.Copy(f(i), DestinationDirectory & "\" & SourceDirectory(f(i)))
            Next
        Catch ex As Exception

        End Try

    End Sub
Re: Using XCOPY dos command in VB.NET 80 80

why so complicated? Try this:

Dim DestinationDirectory As String = "I:\New\Export\ID"
Dim SourceDirectory As String = "C:\Temp2\"
Dim overwrite As boolean = true
my.Computer.FileSystem.CopyDirectory(SourceDirectory,DestinationDirectory,overwrite)
Re: Using XCOPY dos command in VB.NET 80 80

why so complicated? Try this:

Dim DestinationDirectory As String = "I:\New\Export\ID"
Dim SourceDirectory As String = "C:\Temp2\"
Dim overwrite As boolean = true
my.Computer.FileSystem.CopyDirectory(SourceDirectory,DestinationDirectory,overwrite)

Thank you! This does work, but it won't let me copy from my C drive to my I drive. It's saying it can't find the location of the I drive.

Re: Using XCOPY dos command in VB.NET 80 80

The question is:
does this directory "I:\New\Export\ID" already exist?

If Not IO.Directory.Exists(DestinationDirectory) Then
			IO.Directory.CreateDirectory(DestinationDirectory)
		End If
Re: Using XCOPY dos command in VB.NET 80 80

The question is:
does this directory "I:\New\Export\ID" already exist?

If Not IO.Directory.Exists(DestinationDirectory) Then
			IO.Directory.CreateDirectory(DestinationDirectory)
		End If

Yes it exists already.

Re: Using XCOPY dos command in VB.NET 80 80

Please paste the exact error message.

Re: Using XCOPY dos command in VB.NET 80 80

Please paste the exact error message.

System.IO.DirectoryNotFoundException: Could not find a part of the path 'I:\New\Export\ID'.

Re: Using XCOPY dos command in VB.NET 80 80

Is this Drive mapped to a different computer?
If so then change the path to: \\other_computer\New\Export\ID

Re: Using XCOPY dos command in VB.NET 80 80

Is this Drive mapped to a different computer?
If so then change the path to: \\other_computer\New\Export\ID

ok well that error is gone, but now it gives me this one:

System.IO.IOException: Could not complete operation on some files and directories. See the Data property of the exception for more details

Re: Using XCOPY dos command in VB.NET 80 80

and what are the details?

Re: Using XCOPY dos command in VB.NET 80 80

and what are the details?

IOException: Could not complete operation on some files and directories. See the Data property of the exception for more details.]
Microsoft.VisualBasic.FileIO.FileSystem.FxCopyOrMoveDirectory(CopyOrMove operation, String sourceDirectoryPath, String targetDirectoryPath, Boolean overwrite) +296170
Microsoft.VisualBasic.FileIO.FileSystem.CopyOrMoveDirectory(CopyOrMove operation, String sourceDirectoryName, String destinationDirectoryName, Boolean overwrite, UIOptionInternal showUI, UICancelOption onUserCancel) +304
Microsoft.VisualBasic.MyServices.FileSystemProxy.CopyDirectory(String sourceDirectoryName, String destinationDirectoryName, Boolean overwrite) +20
_Export.CopyFiles() in D:\importer\Export_Tool.aspx.vb:176
_Export.Export_Click(Object sender, EventArgs e) in D:\importer\Export_Tool.aspx.vb:134
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Re: Using XCOPY dos command in VB.NET 80 80

did you try to set the credentials for the remote computer? like so:
\\username:password@machinename\directory\to\copy\to

Re: Using XCOPY dos command in VB.NET 80 80

did you try to set the credentials for the remote computer? like so:
\\username:password@machinename\directory\to\copy\to

I would write the string first then set another string as credentials to what you just said?

**sorry I'm kinda new to vb**

Re: Using XCOPY dos command in VB.NET 80 80

did you try to set the credentials for the remote computer? like so:
\\username:password@machinename\directory\to\copy\to

ok how about doing this to login?

Dim p As New System.Diagnostics.Process
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardInput = True
p.StartInfo.FileName = "xcopy.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardError = True
p.StartInfo.WorkingDirectory = "C:\"
p.StartInfo.LoadUserProfile = True
p.StartInfo.UserName = "username"
p.StartInfo.Domain = "pass"
Dim pw As New System.Security.SecureString
For Each ch As Char In (Chr(36) & Chr(111) & Chr(55) & Chr(100) & Chr(105) & Chr(101) & Chr(114) & Chr(115))
pw.AppendChar(ch)
Next
p.StartInfo.Password = pw

p.Start()

Re: Using XCOPY dos command in VB.NET 80 80

i actually meant:
Dim DestinationDirectory As String = "\\username:password@machinename\New\Export\ID"

Re: Using XCOPY dos command in VB.NET 80 80

i actually meant:
Dim DestinationDirectory As String = "\\username:password@machinename\New\Export\ID"

I keep getting the error System.NotSupportedException: The given path's format is not supported.

Re: Using XCOPY dos command in VB.NET 80 80

I'm running out of ideas...I think the best thing to do is, zipping your project and attach it to this thread. so we can take a look on it.

Re: Using XCOPY dos command in VB.NET 80 80

put your code in try catch statement and post your exception message.

Try
            ''your code in here
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
Re: Using XCOPY dos command in VB.NET 80 80

I'm running out of ideas...I think the best thing to do is, zipping your project and attach it to this thread. so we can take a look on it.

I tried your last idea and it worked! Thanks so much!

Re: Using XCOPY dos command in VB.NET 80 80

I'm glad that it helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.