从Web检查丢失的文件并下载丢失的文件

时间:2017-08-05 14:03:58

标签: c#

如何在c#中创建一个系统来检查主机上list.txt中所需文件的列表,并将每个文件分别添加到代码中?

If (! File.Exists ("each file in the list"))
{
   WebClient client = new WebClient ();
   Client.DownloadFileAsync (new Uri (site + "missing file"), dir + "name of downloaded file");
}

1 个答案:

答案 0 :(得分:0)

试试这段代码:

var files = File.ReadAllLines("list.txt");
foreach (var filename in files)
{
    if (!File.Exists(filename))
    {
        WebClient client = new WebClient();
        client.DownloadFileAsync(new Uri(site + filename), dir + filename);
    }
}