-1

I have a folder on my local machine that contains .jpeg files. I want to select all of these images and save them in the other folder. That is all. I am using c# and ASP.NET Webforms. Is there an easy way of doing so?

Thank you.

slrom
  • 144
  • 1
  • 3
  • 11
  • There is.. Have you looked at `File.Copy()` ? – Kevin Mee Jun 10 '15 at 20:26
  • Do you want just copy them in the destination folder or do you want to move them (IE Copy then Delete)? And more important. Are these source and destination folder under the root folder of your site? – Steve Jun 10 '15 at 20:27
  • No root folder. The starting folder and destination folder are on desktop of my local machine. I was simply practicing for the bigger project at hand and had a little problem with selecting files. It works now. – slrom Jun 10 '15 at 20:44

1 Answers1

1

Something like this should do the trick:

var filesToCopy = Directory.EnumerateFiles(@"c:\path to images", "*.jpeg");

var directoryToCopyTo = "c:\destination folder";

foreach (var file in filesToCopy)
{
    File.Copy(file, Path.Combine(directoryToCopyTo, Path.GetFileName(file)));
}

Note: This won't copy images in sub-folders

Dave Bish
  • 19,263
  • 7
  • 46
  • 63