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. [专题总结]初探插头dp

    彻彻底底写到自闭的一个专题. 就是大型分类讨论,压行+宏定义很有优势. 常用滚动数组+哈希表+位运算.当然还有轮廓线. Formula 1: 经过所有格子的哈密顿回路数. 每个非障碍点必须有且仅有2个 ...

  2. kaldi使用thchs30数据进行训练并执行识别操作

    操作系统 : Ubutu18.04_x64 gcc版本 :7.4.0 数据准备及训练 数据地址: http://www.openslr.org/18/ 在 egs/thchs30/s5 建立 thch ...

  3. 【解决】MySQL提示启动成功,实际进程并没有起来

    一.概括: 1.查看运行日志 vim /var/log/mariadb/mariadb.log 2.修改配置文件 vim /etc/my.cnf 3.修改文件权限 chown mysql.mysql ...

  4. 多进程操作-进程队列multiprocess.Queue的使用

    一.ipc机制 进程通讯 管道:pipe 基于共享的内存空间 队列:pipe+锁 queue 下面拿代码来实现Queue如何使用: 案例一: from multiprocessing import Q ...

  5. DataTable实现分组

    有时候我们从数据库中查询出来数据之后,需要按照DataTable的某列进行分组,可以使用下面的方法实现,代码如下: using System; using System.Collections.Gen ...

  6. 查看Oracle被锁的表以及如何解锁

    注意权限问题 1.查看是否有被锁的表: select b.owner,b.object_name,a.session_id,a.locked_modefrom v$locked_object a,db ...

  7. Add a Simple Action using an Attribute 使用特性添加简单按钮

    In the previous Add a Simple Action lesson, you learned how to add an Action by implementing the Vie ...

  8. kafka cmd首个单机例子配置

    下载地址:http://kafka.apache.org/downloads       http://mirror.bit.edu.cn/apache/kafka/2.3.0/kafka_2.12- ...

  9. Linux-打包压缩命令

    内容总结自<鸟哥的Linux私房菜>http://cn.linux.vbird.org/linux_basic/0240tarcompress.php 一.打包/压缩文件常见扩展名 *.g ...

  10. 如何判断Linux系统安装在VMware上?

    如何判断当前Linux系统是否安装在VMware上面呢? 因为公司大部分服务器位于VMware上,也有小部分系统部署在物理机上面.今天老大要求统计一下VMware和物理机上服务器的数量,个人简单测试. ...