0
Dim FilestoCopy As String
Dim NewCopies As String

FilestoCopy = "C:\Users\Documents\*.txt"
NewCopies = "D:\New\Documents\"

If System.IO.File.Exists(FilestoCopy ) = True Then
System.IO.File.Copy(FilestoCopy , NewCopies )
MsgBox("File Copied")
End If

I was wondering how to switch this to copy all .txt file from FilestoCopy to NewCopies

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by GeekByChoiCe
0

You first need to find the files in the first directory and create a list of them. Then loop through the list copying the source files to the destination.

0

Here is an example that will copy all "jpg" files, found in one directory, to another directory.

Dim overwrite As boolean
		Dim destinationFolder As string = "C:\Users\GeekByChoiCe\Desktop\dump"
		Dim files() As String = IO.Directory.GetFiles("C:\Users\GeekByChoiCe\Desktop\myhouse", "*.jpg",io.SearchOption.AllDirectories)
		Array.ForEach(files, Sub(sinfleFile As String)
						  io.File.Copy(sinfleFile,io.Path.Combine(destinationFolder, io.Path.GetFileName(sinfleFile)), overwrite)
							 End Sub)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.