如何将图像复制从一个文件夹共享到另一个文件夹

时间:2014-12-23 10:09:12

标签: c#

当我们将一个文件夹中的图像复制到另一个文件夹时,图像将逐个复制,然后成千上万的图像复制需要更多时间,是否有可能一次复制多个图像? “这是我的代码”

              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);    

1 个答案:

答案 0 :(得分:0)

使用以下代码:

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");
}

}