static void Main(string[] args)
{
var pathSour = "";//@"C:\ClientTest";
var pathDes = "";//@"C:\WorkSpace_Client\Client";
if (args.Length >= 2)
{
pathSour = args[0];//@"C:\ClientTest";
pathDes = args[1];
}
else
{
Console.WriteLine("参数路径到 Client文件夹终止");
Console.WriteLine("参数有误,第一个参数为源文件路径 ,第二个参数是目标目录");
return;
}
var files = GetBuildFiles(pathSour);
ReplaceData(files, pathDes);
}
private static List<string> GetBuildFiles(string path)
{
var directories = Directory.GetDirectories(path);
var files = Directory.GetFiles(path).ToList();
foreach (var directory in directories)
{
var name = Path.GetFileName(directory);
files.AddRange(GetBuildFiles(directory));
}
return files;
}
public static void ReplaceData(List<string> files,string pathDest)
{
pathDest = pathDest.Replace("\\","/");
foreach (var file in files)
{
var path = file.Replace("\\", "/");
var spStr = "Assets";
var pos = path.IndexOf(spStr);
var posEnd = path.Substring(pos);
var fullDestPath = Path.Combine(pathDest, posEnd).Replace("\\", "/");
if (File.Exists(fullDestPath))
{
File.Copy(path, fullDestPath, true);
Console.WriteLine("replace Ok fullDestPath ="+ fullDestPath);
}
else
{
File.Copy(path, fullDestPath, true);
Console.WriteLine(" copy Ok fullDestPath =" + fullDestPath);
}
}
}
}
C#(一)相对路径copy文件
最新推荐文章于 2023-06-13 15:44:29 发布