我有IIS部署的网站上我有虚拟文件夹包含文件夹和文件。 我正在使用以下代码从Http站点复制文件。但我一次只复制一个文件。而不是一个接一个地处理文件我想复制所有目录。如何从Http目录复制所有文件?
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
可能会帮助您http://stackoverflow.com/questions/124492/c-sharp-httpwebrequest-command-to-get-directory-listing – kaushik0033
请参阅链接:http://www.codeproject.com/Articles/34415 /正在下载 - 通过HTTP连接的多文件 – kaushik0033
@ kaushik0033:我明白了。老兄谢谢!该目录中的 –