C# copy files from source directory to destination file and rename repeated files and does not override
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的更多相关文章
- File、Paths和Files类的使用详解
Paths:通过get()方法返回一个Path对象,Path用于表示文件路径和文件. Files:提供了大量处理文件的方法,例如文件复制.读取.写入,获取文件属性.快捷遍历文件目录等..... Fil ...
- 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 ...
- [Windows API] Listing the Files in a Directory,可用来数文件夹下有多少个子文件(夹)
转载 #include <windows.h> #include <tchar.h> #include <stdio.h> #include <strsafe ...
- 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 ...
- 网站访问出现 ------ Can not write to cache files, please check directory ./cache/ .
最近在搞微商城时,突然出现了Can not write to cache files, please check directory ./cache/ .这样一个提示, 但最近好像没搞什么大动作,怎么 ...
- 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 ...
- LeetCode 1059. All Paths from Source Lead to Destination
原题链接在这里:https://leetcode.com/problems/all-paths-from-source-lead-to-destination/ 题目: Given the edges ...
- 解决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 ...
- 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- ...
随机推荐
- 网络编程懒人入门(十):一泡尿的时间,快速读懂QUIC协议
1.TCP协议到底怎么了? 现时的互联网应用中,Web平台(准确地说是基于HTTP及其延伸协议的客户端/服务器应用)的数据传输都基于 TCP 协议. 但TCP 协议在创建连接之前需要进行三次握手(如下 ...
- IT兄弟连 HTML5教程 CSS3揭秘 CSS3属性3
5 用户界面属性 在CSS3中,新的用户界面特性包括重设元素尺寸.盒尺寸及轮廓等.本小节着重介绍一下resize属性,只有Firefox 4和Safari 3浏览器支持此属性.resize属性可用于重 ...
- Spring Boot MVC api返回的String无法关联到视图页面
1:问题 使用 @Restcontroller 返回值定义为String 时 无法返回具体的页面 @RestController public class HelloController { @Get ...
- C和C++常见误区以及问题整理
c和c++的关系 c是面向过程的语言,c++是在c的基础上扩展的面向对象的编程语言. c++具备c的所有功能,对c的库完全兼容. c++的标准在98年确定,在那之前已经有一些库大量使用. 新标准中,推 ...
- Python 爬虫从入门到进阶之路(四)
之前的文章我们做了一个简单的例子爬取了百度首页的 html,我们用到的是 urlopen 来打开请求,它是一个特殊的opener(也就是模块帮我们构建好的).但是基本的 urlopen() 方法不支持 ...
- 多线程十 Timer
定时/计算在java中主要使用的是Timer对象,他的内部依然是采用多线程方式进行处理 它有四个构造方法 方法名 作用 Timer() 空参 Timer(String name) 指定名字 Timer ...
- 如何关闭jdk自动更新提示
缘由 国庆将电脑重装了一下,jdk自然也就重装了,一开机总是提示我更新,索性就将他关掉. 解决办法 右键这个图标,点击属性. 将自动更新取消勾选.
- 用户APC的执行过程
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html 用户APC的执行过程 一.一个启发式问题 有一个问题,线程什么时候 ...
- Python中的常见特殊方法—— repr方法
在Python中有些方法名.属性名的前后都添加了双下划线,这种方法.属性通常都属于Python的特殊方法和特殊属性,开发者可以通过重写这些方法或者直接调用这些方法来实现特殊的功能.其实前面见过的构造方 ...
- Scrapy框架的简单使用
一.安装依赖 #Windows平台 1.pip3 install wheel 3.pip3 install lxml 4.pip3 install pyopenssl 5.pip3 install p ...