Re: How to copy files using c#?

  • Thread starter Thread starter Mihai Virtosu
  • Start date Start date
M

Mihai Virtosu

Maarten,

What about copying multiple files, with wildcards (and
not using the Directory class)?

Mihai
 
To select multiple files use the DirectoryInfo.GetFiles method which accepts
a wildcard pattern. This will return an array of filenames. You can then use
a foreach loop to copy these files e.g.

DirectoryInfo di = new DirectoryInfo("\\My Documents");

FileInfo[] filelist = di.GetFiles("*.txt");

foreach(FileInfo file in filelist)
{
File.Copy(file.DirectoryName + "\\" + file.Name, "\\Program Files\\My
Application\\" + file.Name);
}

Copies all text files in my documents to an application folder.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
 
Back
Top