0

When we are copying images in one folder to another folder, images are going to copy one by one, then it takes more time when thousands's of images are copying, Is there any Possibility to copy Multiple images at a time? "This is My code"

              int avilableCharts = 0;
              int unavialableCharts = 0;
              string chartid;
              int count = 0;
                StreamReader rd = new StreamReader(txtFileName.Text);
                StreamWriter tw = new StreamWriter("C:\\LogFiles\\SucessfullyMovedImages.txt");
                StreamWriter tw1 = new StreamWriter("C:\\LogFiles\\UnavailableImages.txt");
                DirectoryInfo dirinfo = new DirectoryInfo(txtSourceFolder.Text);
                FileInfo[] file = dirinfo.GetFiles("*.pdf");
                while (!rd.EndOfStream)
                {
                    chartid = rd.ReadLine() + ".pdf";
                    count = count + 1;
                    worker.ReportProgress(count);
                    string FName = string.Empty;                      
                    if (File.Exists(txtSourceFolder.Text + chartid))

                    {
                        File.Copy(txtSourceFolder.Text + chartid , txtDestinationFolder.Text +          chartid );
                        avilableCharts = avilableCharts + 1;
                        tw.WriteLine(chartid);                            
                    }
                    else
                    {
                        unavialableCharts = unavialableCharts + 1;
                        tw1.WriteLine(chartid);
                    }

                }
                tw.Close();
                tw1.Close();
                MessageBox.Show("Successfully Copied Images are :" + avilableCharts);
                MessageBox.Show("Total Unavilable Images are : " + unavialableCharts);    
  • how are you copying the images? – Harry Dec 23 '14 at 10:10
  • possible duplicate of [Folder copy in C#](http://stackoverflow.com/questions/1974019/folder-copy-in-c-sharp) – Kumar Manish Dec 23 '14 at 10:12
  • 1
    Please existing code... or things you have already researched and / or tried. In general, yes it is possible to copy multiple images at a time.. but there are several ways of doing it.. Please try to narrow down your question. – Vikas Gupta Dec 23 '14 at 10:15
  • i am giving needed images numbers in one text file, based on that it will search in images folder, then i am copying to another folder(By using while loop and File.copy) – P C K V Prasad babu Mandadapu Dec 23 '14 at 10:16

1 Answers1

0

use below code :

public class SimpleFileMove
 {
  static void Main()
   {
    string sourceFile = @"C:\Users\Public\public\test.txt";
    string destinationFile = @"C:\Users\Public\private\test.txt";

    // To move a file or folder to a new location:
    System.IO.File.Move(sourceFile, destinationFile);

    // To move an entire directory. To programmatically modify or combine
    // path strings, use the System.IO.Path class.
    System.IO.Directory.Move(@"C:\Users\Public\public\test\", @"C:\Users\Public\private");
}

}

Kumar Manish
  • 3,746
  • 3
  • 37
  • 42