0

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
3
Contributors
19
Replies
27
Views
5 Years
Discussion Span
Last Post by bluehangook629
0

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)
0

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.

0

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
0

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.

0

Please paste the exact error message.

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

0

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

0

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

0

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

0

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**

0

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()

0

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.

0

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.

0

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
0

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!

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.