我有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:我明白了。老兄謝謝!該目錄中的 –