使用robo复制和处理进行文件复制 [英] File copy using robo copy and process

查看:298
本文介绍了使用robo复制和处理进行文件复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个文件复制程序,它将使用ROBOCOPY命令复制大量文件(约100,000个),大小约为50 KB。

I am creating a File copy program which will copy large number of files(~100,000) with size ~50 KB using ROBOCOPY command.

对于每个文件,我正在创建一个新进程并传递ROBOCOPY命令和参数,如下所示:

For each file, I am creating a new process and passing the ROBOCOPY command and arguments as follow:

using (Process p = new Process)
{
    p.StartInfo.Arguments = string.Format("/C ROBOCOPY {0} {1} {2}", 
            sourceDir, destinationDir, fileName);
    p.StartInfo.FileName = "CMD.EXE";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.UseShellExecute = false;                    
    p.Start();
    p.WaitForExit(); 
} 

我正在寻找一种更好的方法,而不是为每个文件创建一个流程,这在性能和设计方面都会很好。有人可以建议一个更好的方法吗?

Instead of creating a process for each file, I am looking for a better approach, which will be good in terms of performance and design. Can someone suggest a better method?

推荐答案

我只会使用System.IO。应该足够快,并且文件名可以是通配符。

I would just use System.IO. Should be plenty fast enough, and your filename could be a wildcard.

using System.IO;
// snip your code... providing fileName, sourceDir, destinationDir
DirectoryInfo dirInfo = new DirectoryInfo(sourceDir);
FileInfo[] fileInfos = dirInfo.GetFiles(fileName);
foreach (FileInfo file in fileInfos)
{
    File.Copy(file.FullName, Path.Combine(destinationDir, file.Name), true);  // overwrites existing
}

这篇关于使用robo复制和处理进行文件复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆