Click here to Skip to main content
15,035,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Try To Use
A Faster File.Copy[^]
This Code Convert visual basic But if ı use this code code give
"empty path name is not legal Error"
How Can ı Fix This Converted Code?
Note:I convert this Code with Code Converter C# to VB and VB to C# – Telerik[^]

What I have tried:

Public Shared Sub MoveTime(ByVal source As String, ByVal destination As String)
    Dim start_time As DateTime = DateTime.Now
    FMove(source, destination)
    Dim size As Long = New FileInfo(destination).Length
    Dim milliseconds As Integer = 1 + CInt(((DateTime.Now - start_time).TotalMilliseconds))
    Dim tsize As Long = size * 3600000 / milliseconds
    tsize = tsize / CInt(Math.Pow(2, 30))
    Console.WriteLine(tsize & "GB/hour")
End Sub

Private Shared Sub FMove(ByVal source As String, ByVal destination As String)
    Dim array_length As Integer = CInt(Math.Pow(2, 19))
    Dim dataArray As Byte() = New Byte(array_length - 1) {}

    Using fsread As FileStream = New FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None, array_length)

        Using bwread As BinaryReader = New BinaryReader(fsread)

            Using fswrite As FileStream = New FileStream(destination, FileMode.Create, FileAccess.Write, FileShare.None, array_length)

                Using bwwrite As BinaryWriter = New BinaryWriter(fswrite)

                    While True
                        Dim read As Integer = bwread.Read(dataArray, 0, array_length)
                        If 0 = read Then Exit For
                        bwwrite.Write(dataArray, 0, read)
                    End While
                End Using
            End Using
        End Using
    End Using

End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim Sourcefolder As String = FolderBrowserDialog1.SelectedPath
    Dim Tragetfolder As String = FolderBrowserDialog2.SelectedPath
    FMove(Sourcefolder, Tragetfolder)
End Sub
Updated 4-Mar-21 19:49pm

1 solution

At a guess - and without the code that calls it that's all it can be - one of the two string parameters you pass is empty, so the system rightly says "That isn't a valid file path".

Use the debugger, put a breakpoint on the first line in the method, and check exactly what you are passing.

Sorry, but we can't do that for you - time for you to learn a new skill: debugging!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900