0
我想從一個文件夾中的文件複製並粘貼在其他創建的文件夾複製文件從文件夾複製到另一個用C#
我已經創建的文件夾下面的代碼:
DirectoryInfo di = Directory.CreateDirectory(path);
其中path是創建文件夾的路徑。
我怎樣才能用這個文件夾填充另一個文件夾中的文件。
感謝
我想從一個文件夾中的文件複製並粘貼在其他創建的文件夾複製文件從文件夾複製到另一個用C#
我已經創建的文件夾下面的代碼:
DirectoryInfo di = Directory.CreateDirectory(path);
其中path是創建文件夾的路徑。
我怎樣才能用這個文件夾填充另一個文件夾中的文件。
感謝
這將找到並複製以指定的搜索PARAM文件。
public static void findAndCopy(string _sourcePath, string _destPath, string _searchParam)
{
if (System.IO.Directory.Exists(_sourcePath))
{
string[] files = System.IO.Directory.GetFiles(_sourcePath, _searchParam, System.IO.SearchOption.AllDirectories);
string destFile = "";
string fileName = "";
// Copy the files
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(_destPath, fileName);
try
{
System.IO.File.Copy(s, destFile, false);
}
catch (UnauthorizedAccessException uae)
{
log.Warn(uae);
}
catch (IOException ioe)
{
log.Warn(ioe);
}
}
}
else
{
log.Error("Source path not found! " + _sourcePath);
}
}//end findAndCopy