File.Copy Method

  • Thread starter Thread starter Jul
  • Start date Start date
J

Jul

File.Copy Method does not let use template for copying files,
I can not use File.Copy("C:\ABC\*.txt", "C:\XYZ\*.txt")

but I need to use such way:
File.Copy("C:\ABC\1.txt", "C:\XYZ\1.txt")
File.Copy("C:\ABC\2.txt", "C:\XYZ\2.txt")

Does exist way in .Net for copying file by template?
 
File.Copy Method does not let use template for copying files,
I can not use File.Copy("C:\ABC\*.txt", "C:\XYZ\*.txt")


Use the File.Directory.GetFiles method to filter your directory.

Then call File.Copy for each item in GetFiles.
 
You'll have to loop through the directory and copy the files one by one:

Dim SourceDir As String = "C\ABC"
Dim DestDir As String = "C:\XYZ"
Dim DestFile As String

For Each strFile As String In Directory.GetFiles(SourceDir, "*.txt")
DestFile = strFile.Replace(SourceDir, DestDir)
File.Copy(strFile, DestFile)
Next strFile


hope that helps..
Imran.
 
Back
Top