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

Recommended Answers

All 2 Replies

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.

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)
Be a part of the DaniWeb community

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