Below is not a catalog.
Dim sourcepath As String = "C:\temp\test\1.txt"
Because you use it as a directory in Directory.GetFiles(sourcePath)
.
In addition, I recommend telling you more about your questions next time. Significant exceptions occur in the code, such as a DirectoryNotFoundException
with the corresponding path in the form of a message or (if the file exists) an IOException
with the message "Invalid directory name". You should have added this to the question.
So the solution is simply to remove 1.txt
from the directory-name:
Dim sourcepath As String = "C:\temp\test\"
If you need to copy only one file, use the CopyTo method :
Dim sourcepath As String = "C:\temp\test\" Dim DestPath As String = "C:\temp\Data\" If Not Directory.Exists(DestPath) Then Directory.CreateDirectory(DestPath) End If Dim file = New FileInfo("C:\temp\test\1.txt") file.CopyTo(Path.Combine(DestPath, file.Name), True)
source share