需求
最近遇到一个需求,需要把做一个生成exe的工具,用了一个取巧的方法,把现有的工具复制到指定位置,因为功能基本都一样只是每次要生成不同的配置文件,主体运行程序是一样的。
实现
这里就用到了文件操作中的复制文件夹中的所有内容到另一个文件夹,这里的源文件夹是我的主程序在的位置,目标文件夹则是我要批量生成程序的地方
```csharp
/// <summary>
/// 复制文件夹中的所有文件夹与文件到另一个文件夹
/// </summary>
/// <param name="sourcePath">源文件夹</param>
/// <param name="destPath">目标文件夹</param>
public static void CopyFolder(string sourcePath, string destPath)
{
if (Directory.Exists(sourcePath))
{
if (!Directory.Exists(destPath))
{
//目标目录不存在则创建
try
{
Directory.CreateDirectory(destPath);
}
catch (Exception ex)
{
t