C# copy files from source directory to destination file and rename repeated files and does not overr(cctv5在线直播观看)

网友投稿 258 2022-07-31

static void CopyFiles()

{

string sourceDir = @"D:\C\ll";

string destDir = @"D:\LL";

if (!Directory.Exists(destDir))

{

Directory.CreateDirectory(destDir);

}

string[] mp3Files= Directory.GetFiles(sourceDir, "*.mp3", SearchOption.AllDirectories);

if(mp3Files!=null && mp3Files.Any())

{

Dictionary dic = new Dictionary();

List repeatedList = new List();

foreach (string mp3 in mp3Files)

{

string mp3FileName = Path.GetFileName(mp3);

string newMp3FileName = Path.GetFileName(mp3);

if (dic.ContainsKey(mp3FileName))

{

string guid = Guid.NewGuid().ToString().Substring(0, 6);

newMp3FileName = Path.GetFileNameWithoutExtension(mp3FileName) + guid + ".mp3";

dic.Add(newMp3FileName, newMp3FileName);

string repeatedMsg = $"mp3:{mp3},newMp3FileName:{newMp3FileName}";

repeatedList.Add(repeatedMsg);

}

else

{

dic.Add(mp3FileName, mp3FileName);

}

string newMp3FullName = Path.Combine(destDir, newMp3FileName);

File.Copy(mp3, newMp3FullName, false);

Console.WriteLine($"oldmp3:{mp3},newMp3FullName:{newMp3FullName}");

}

dic = null;

Console.WriteLine($"\n\n There are {repeatedList.Count} Repeated Msg:");

repeatedList.ForEach(x =>

{

Console.WriteLine(x);

});

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Winform中在使用VS+svn进行协同开发时添加引用时的相对路径和绝对路径的问题
下一篇:C#如何判断委托是实例方法还是静态方法(乘风破浪的姐姐第三季)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~