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<string, string> dic = new Dictionary<string, string>();
List<string> repeatedList = new List<string>();
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(, );
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);
});
}
}

C# copy files from source directory to destination file and rename repeated files and does not override的更多相关文章

  1. File、Paths和Files类的使用详解

    Paths:通过get()方法返回一个Path对象,Path用于表示文件路径和文件. Files:提供了大量处理文件的方法,例如文件复制.读取.写入,获取文件属性.快捷遍历文件目录等..... Fil ...

  2. Solved Unable to copy the source file ./installer/services.sh to the destination file /etc/vmware-t

    Sometimes when you intall vmwaretools there will be some problems such as "Unable to copy the s ...

  3. [Windows API] Listing the Files in a Directory,可用来数文件夹下有多少个子文件(夹)

    转载 #include <windows.h> #include <tchar.h> #include <stdio.h> #include <strsafe ...

  4. How do I list the files in a directory?

    原文地址:How do I list the files in a directory? You want a list of all the files, or all the files matc ...

  5. 网站访问出现 ------ Can not write to cache files, please check directory ./cache/ .

    最近在搞微商城时,突然出现了Can not write to cache files, please check directory ./cache/ .这样一个提示, 但最近好像没搞什么大动作,怎么 ...

  6. mysql配置文件夹错误:在安装mysql 5.6.19 时运行cmake命令是出现CMake Error: The source directory does not appear to contai

    在安装mysql 5.5.xx 时运行cmake命令是出现CMake Error: The source directory does not appear to contain CMakeLists ...

  7. LeetCode 1059. All Paths from Source Lead to Destination

    原题链接在这里:https://leetcode.com/problems/all-paths-from-source-lead-to-destination/ 题目: Given the edges ...

  8. 解决Cannot find config.m4 Make sure that you run '/home/php/bin/phpize' in the top level source directory of the module

    oot@DK:/home/daokr/downfile/php-7.0.0/ext/mysqlnd# /home/php/bin/phpizeCannot find config.m4. Make s ...

  9. armv7a-mediatek451_001_vfp-linux-gnueabi-gcc: directory: No such file or directory 编译error

    release/vm_linux/output/hisense_android/mt5399_cn_android_JB/rel/obj/oss/source/arm_mali_ko/mali400- ...

随机推荐

  1. atom 在Ubuntu 18.04 上安装及基本使用

    前记: Atom 是github专门为程序员推出的一个跨平台文本编辑器.具有简洁和直观的图形用户界面,并有很多有趣的特点:支持CSS,HTML,JavaScript等网页编程语言.它支持宏,自动完成分 ...

  2. php中Session使用方法详解

    Session的声明与使用 Session的设置不同于Cookie,必须先启动,在PHP中必须调用session_start().session_start()函数的语法格式如下: Bool sess ...

  3. table-layout:fixed

    table-layout: fixed; 在table上设置上面属性后,如果不设置td的宽度,那么所有td的宽度平分总table宽度.如果设置了td的宽度,则以设置的宽度为准. table-layou ...

  4. 用 Python 实现植物大战僵尸代码!

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: marble_xu GitHub地址:https://github ...

  5. 【C++常用函数】头文件<algorithm>中的常用函数(绝对值,交换,比较)

    swap(a,b) 用于交换a,b两个变量的值: max(a,b) 返回a,b中的最大值: min(a,b) 返回a,b中的最小值: abs(x) 返回x的绝对值,x必须是整数:

  6. Java分布式系统---消息中间件

    简介 消息中间件也可以称消息队列,是指用高效可靠的消息传递机制进行与平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息队列模型,可以在分布式环境下扩展进程的通信.当下主流 ...

  7. Oracle数据库之第四篇

    /* 授权命令 grant 权限 to 用户 授权可以授予多个权限 grant connect,resource to baidu 收回权限 revoke 权限 from 用户 revoke dba ...

  8. http请求post,文件导出兼容IE10+

    1.post的方法里要加responseType: 'blob'参数,不然下载的excel会乱码 2.使用{type: "application/vnd.ms-excel"}的写法 ...

  9. ASP.NET Core 设置默认起始页(如default.html)

    测试页面foo.html 在Startup.cs内使用middleware 代码如下: DefaultFilesOptions defaultFilesOptions = new DefaultFil ...

  10. 如何查找jdk安装路径也就是JAVA_HOME配置的环境变量