1
我有一个配置文件,其中包含我想要下载的URI列表。例如,下载文件并创建与主机相同的文件夹结构
http://xyz.abc.com/Dir1/Dir3/sds.txt
http://xyz.abc.com/Dir2/Dir4/jhjs.txt
http://xyz.abc.com/Dir1/itr.txt
我想读取配置文件,并复制每个URL,但在同一时间创建相同的目录结构的主机上。例如,对于配置文件中的第一行,我想在本地机器上创建目录结构Dir1/Dir3(如果它不存在),然后将sds.exe复制到.../Dir1/Dir3/
如何在C#中执行此操作?
什么我至今是:
string myStringWebResource; //Read this from the config file
System.IO.StreamReader file =
new System.IO.StreamReader("config.txt");
// Read the config file line by line
while ((myStringWebResource = file.ReadLine()) != null)
{
// Create a new WebClient instance.
using (WebClient myWebClient = new WebClient())
{
//How do I keep the original filename, e.g. sds.txt
string outputFilename = @"" + ???";
Console.WriteLine("Downloading ...");
// Download the Web resource and save it into
// the current filesystem folder.
try
{
myWebClient.DownloadFile(myStringWebResource, outputFilename);
Console.WriteLine("Successful");
}
catch (WebException e)
{
Console.WriteLine("Fail" + e.Message);
}
}
}
虽然这让我下载配置文件中的所有文件,
- 我有下载后他们的名字,怎么这个问题我可以保留原来的名字吗?
- 所有文件都下载到同一个文件夹中。我怎么能从主机复制文件夹结构?
那很好。但你能告诉我如何过滤出主机 –