说明(2017-11-17 14:46:05):

1. 因为经常要从U盘里面删除版本,然后添加版本,每次都要几个人手动复制粘贴,费时费力,就花了一下午时间写了个程序,自动删除和添加版本。

2. DriverInfo类可以识别插到电脑的U盘,还能识别U盘容量。

3. 现在是先全部删除选中版本,再一个U盘一个U盘的往里拷贝,不知道用多线程是否能同时拷贝。

4. 如果遇到有一个U盘不能读取,软件会报错,提示未检测到路径,可以加个判断,判断一下U盘路径是否存在。不过我懒得改了,用之前先用刻盘软件检查一下有没有坏盘就好了。

5. 如果遇到里面已经存在这个版本了,目前是直接覆盖,不然会报错提示文件已存在,这里也可以判断一下是否存在这个文件,我也懒得改了。

6. 用c#在Windows系统操作文件还是很方便的,也不用找这个库那个库,我猜想如果用python做,估计找库就得找死,而且也没什么界面。

软件界面:

Form1.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Text.RegularExpressions;
  11.  
  12. namespace ChangeBin
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. //主程序
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. ShowSource();
  24. List<string> UdiskNames = GetUdiskNames();
  25. //foreach (string udiskName in UdiskNames)
  26. //{
  27. // Console.WriteLine(udiskName);
  28. //}
  29.  
  30. }
  31.  
  32. private string[] GetInsertFileName()
  33. {
  34. List<string> fileNames = new List<string>();
  35. string[] chineseFile = Directory.GetFiles("../../res/1_语文");
  36. string[] mathFile = Directory.GetFiles("../../res/2_数学");
  37. string[] englishFile = Directory.GetFiles("../../res/3_英语");
  38.  
  39. foreach (string name in chineseFile)
  40. {
  41. fileNames.Add(name);
  42. }
  43. foreach (string name in mathFile)
  44. {
  45. fileNames.Add(name);
  46. }
  47. foreach (string name in englishFile)
  48. {
  49. fileNames.Add(name);
  50. }
  51. return fileNames.ToArray();
  52.  
  53. }
  54. //全选右侧
  55. private void cb7_CheckedChanged(object sender, EventArgs e)
  56. {
  57. if (cb7.Checked)
  58. {
  59. for (int i = ; i < clb4.Items.Count; i++)
  60. {
  61. clb4.SetItemChecked(i, true);
  62. }
  63. for (int i = ; i < clb5.Items.Count; i++)
  64. {
  65. clb5.SetItemChecked(i, true);
  66. }
  67. for (int i = ; i < clb6.Items.Count; i++)
  68. {
  69. clb6.SetItemChecked(i, true);
  70. }
  71. }
  72. else
  73. {
  74. for (int i = ; i < clb4.Items.Count; i++)
  75. {
  76. clb4.SetItemChecked(i, false);
  77. }
  78. for (int i = ; i < clb5.Items.Count; i++)
  79. {
  80. clb5.SetItemChecked(i, false);
  81. }
  82. for (int i = ; i < clb6.Items.Count; i++)
  83. {
  84. clb6.SetItemChecked(i, false);
  85. }
  86. }
  87.  
  88. }
  89.  
  90. //清除左侧
  91. private void btnClear1_Click(object sender, EventArgs e)
  92. {
  93. for (int i = ; i < clb1.Items.Count; i++)
  94. {
  95. clb1.SetItemChecked(i, false);
  96. }
  97. for (int i = ; i < clb2.Items.Count; i++)
  98. {
  99. clb2.SetItemChecked(i, false);
  100. }
  101. for (int i = ; i < clb3.Items.Count; i++)
  102. {
  103. clb3.SetItemChecked(i, false);
  104. }
  105. }
  106.  
  107. //显示进度
  108. private void cbShowBack_CheckedChanged(object sender, EventArgs e)
  109. {
  110. BackGround bg = new BackGround();
  111. bg.Show();
  112. }
  113.  
  114. //获取U盘里的需要删除的文件路径(怎么获取U盘容量??????名字 ??)
  115. private List<string> GetUdiskNames()
  116. {
  117. List<string> diskNames = new List<string>();
  118. DriveInfo[] driveInfo = DriveInfo.GetDrives();
  119. //15711846400byte
  120. foreach (DriveInfo d in driveInfo)
  121. {
  122. if (d.DriveType == DriveType.Removable)
  123. {
  124. diskNames.Add(d.Name);
  125. }
  126. }
  127. return diskNames;
  128. }
  129.  
  130. //显示主页面
  131. private void ShowSource()
  132. {
  133. //获取需要拷贝的bin包名字和路径
  134. string[] chineseFile = Directory.GetFiles("../../res/1_语文");
  135. string[] mathFile = Directory.GetFiles("../../res/2_数学");
  136. string[] englishFile = Directory.GetFiles("../../res/3_英语");
  137.  
  138. List<string> chineseFileName = new List<string>();
  139. List<string> mathFileName = new List<string>();
  140. List<string> englishFileName = new List<string>();
  141. foreach (string name in chineseFile)
  142. {
  143. chineseFileName.Add(Regex.Split(name, @"1_语文\\")[]);
  144. }
  145. foreach (string name in mathFile)
  146. {
  147. mathFileName.Add(Regex.Split(name, @"2_数学\\")[]);
  148. }
  149. foreach (string name in englishFile)
  150. {
  151. englishFileName.Add(Regex.Split(name, @"3_英语\\")[]);
  152. }
  153. //把需要拷贝的文件名加入选择列表
  154. clb4.Items.AddRange(chineseFileName.ToArray());
  155. clb5.Items.AddRange(mathFileName.ToArray());
  156. clb6.Items.AddRange(englishFileName.ToArray());
  157. }
  158.  
  159. //获取删除列表
  160. private List<string> GetDeleteList()
  161. {
  162. List<string> UdiskNames = GetUdiskNames();
  163. List<string> delNames = new List<string>();
  164. List<string> delPaths = new List<string>();
  165. foreach (var item in clb1.CheckedItems)
  166. {
  167. delNames.Add(item.ToString());
  168. }
  169. foreach (var item in clb2.CheckedItems)
  170. {
  171. delNames.Add(item.ToString());
  172. }
  173. foreach (var item in clb3.CheckedItems)
  174. {
  175. delNames.Add(item.ToString());
  176. }
  177. foreach (string udiskName in UdiskNames)
  178. {
  179. foreach (string delName in delNames)
  180. {
  181. if (delName.Contains("语文"))
  182. {
  183. delPaths.Add(udiskName + @"Root\Data\res\1_语文\" + delName + @".bin");
  184. }
  185. else if (delName.Contains("数学"))
  186. {
  187. delPaths.Add(udiskName + @"Root\Data\res\2_数学\" + delName + @".bin");
  188. }
  189. else if (delName.Contains("英语"))
  190. {
  191. delPaths.Add(udiskName + @"Root\Data\res\3_英语\" + delName + @".bin");
  192. }
  193.  
  194. }
  195. }
  196. return delPaths;
  197. }
  198. //获取插入列表
  199. private List<string> GetInsertList()
  200. {
  201. List<string> InsertList = new List<string>();
  202. //获取需要拷贝的bin包名字和路径
  203. string[] chineseFile = Directory.GetFiles("../../res/1_语文");
  204. string[] mathFile = Directory.GetFiles("../../res/2_数学");
  205. string[] englishFile = Directory.GetFiles("../../res/3_英语");
  206. foreach (string file in chineseFile)
  207. {
  208. InsertList.Add(file);
  209. }
  210. foreach (string file in mathFile)
  211. {
  212. InsertList.Add(file);
  213. }
  214. foreach (string file in englishFile)
  215. {
  216. InsertList.Add(file);
  217. }
  218. foreach (string item in InsertList)
  219. {
  220. Console.WriteLine(item);
  221. }
  222. return InsertList;
  223. }
  224.  
  225. //点击开始,开始删除,插入(要不要分开进行?????)
  226. private void btnStart_Click(object sender, EventArgs e)
  227. {
  228. //删除
  229. List<string> UdiskNames = GetUdiskNames();
  230. List<string> delPaths = GetDeleteList();
  231. if (delPaths.Count > )
  232. {
  233. foreach (string delPath in delPaths)
  234. {
  235. //Console.WriteLine(delPath);
  236.  
  237. if (File.Exists(delPath))
  238. {
  239. File.Delete(delPath);
  240. Console.WriteLine("已删除" + delPath);
  241. }
  242. else
  243. {
  244. //为啥删完还会显示不存在?循环了两次?还是delPath里面存了两遍?
  245. Console.WriteLine(delPath + "不存在");
  246. }
  247.  
  248. }
  249. }
  250. else
  251. {
  252. MessageBox.Show("没有要删除的bin");
  253. }
  254. //插入
  255. //获取需要拷贝的bin包名字和路径
  256. List<string> insertList = GetInsertList();
  257. List<string> chineseFileName = new List<string>();
  258. List<string> mathFileName = new List<string>();
  259. List<string> englishFileName = new List<string>();
  260.  
  261. if (insertList.Count > )
  262. {
  263. foreach (string uDiskName in UdiskNames)
  264. {
  265. foreach (string insertFile in insertList)
  266. {
  267. if (File.Exists(insertFile))
  268. {
  269. string desFileName = null;
  270. string insertFileName = null;
  271. if (insertFile.Contains("语文"))
  272. {
  273. insertFileName = Regex.Split(insertFile, @"1_语文\\")[];
  274. desFileName = uDiskName + @"Root\Data\res\1_语文\" + insertFileName;
  275. }
  276. else if (insertFile.Contains("数学"))
  277. {
  278. insertFileName = Regex.Split(insertFile, @"2_数学\\")[];
  279. desFileName = uDiskName + @"Root\Data\res\2_数学\" + insertFileName;
  280. }
  281. else if (insertFile.Contains("英语"))
  282. {
  283. insertFileName = Regex.Split(insertFile, @"3_英语\\")[];
  284. desFileName = uDiskName + @"Root\Data\res\3_英语\" + insertFileName;
  285. }
  286. if (desFileName != null)
  287. {
  288. //第三个参数是否允许覆盖???
  289. File.Copy(insertFile, desFileName,true);
  290. Console.WriteLine("已插入:" + desFileName);
  291. }
  292. }
  293. else
  294. {
  295. Console.WriteLine("插入文件:" + insertFile + "不存在");
  296. }
  297. }
  298. }
  299.  
  300. }
  301. MessageBox.Show("拷贝完毕!");
  302. }
  303. }
  304. }

C#学习笔记(25)——用刻盘器批量从U盘删除添加文件的更多相关文章

  1. IOS学习笔记25—HTTP操作之ASIHTTPRequest

    IOS学习笔记25—HTTP操作之ASIHTTPRequest 分类: iOS2012-08-12 10:04 7734人阅读 评论(3) 收藏 举报 iosios5网络wrapper框架新浪微博 A ...

  2. JVM学习笔记-第三章-垃圾收集器与内存分配策略

    JVM学习笔记-第三章-垃圾收集器与内存分配策略 tips:对于3.4之前的章节可见博客:https://blog.csdn.net/sanhewuyang/article/details/95380 ...

  3. Linux学习笔记(4)磁盘分区(fdisk)、挂载与文件系统命令

    Linux学习笔记(4)磁盘分区(fdisk).挂载与文件系统命令 1.磁盘分区是怎么表示的? 1.1 对于IDE接口,第一主盘为hda,第1从盘为hdb,第1从盘的第1个分区为hdb1 1.2 对于 ...

  4. linux命令学习笔记(25):linux文件属性详解

    Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组. 最近访问或修改的时间等内容.具体情况如下: 命令: ls -lih 输出: [root@loc ...

  5. ‎Cocos2d-x 学习笔记(25) 渲染 绘制 Render

    [Cocos2d-x]学习笔记目录 本文链接:https://www.cnblogs.com/deepcho/p/cocos2dx-render.html 1. 从程序入口到渲染方法 一个Cocos2 ...

  6. Docker技术入门与实战 第二版-学习笔记-8-网络功能network-3-容器访问控制和自定义网桥

    1)容器访问控制 容器的访问控制,主要通过 Linux 上的 iptables防火墙来进行管理和实现. iptables是 Linux 上默认的防火墙软件,在大部分发行版中都自带. 容器访问外部网络 ...

  7. [原创]java WEB学习笔记25:MVC案例完整实践(part 6)---新增操作的设计与实现

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  8. python学习笔记(5)--迭代器,生成器,装饰器,常用模块,序列化

    生成器 在Python中,一边循环一边计算的机制,称为生成器:generator. 如: >>> g = (x * x for xin range(10)) >>> ...

  9. LearnOpenGL学习笔记(四)——着色器类编写

    之前我们将着色器的代码用glsl写好之后,保存为字符串指针,然后用一个函数去编译它,这是一种手段,对于简单的着色器代码可以这样.但当我们针对复杂的着色器,我们发现编写.编译.管理着色器是一件麻烦事.我 ...

随机推荐

  1. POJ 2337 Catenyms (欧拉回路)

    Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 2149 Descript ...

  2. React(0.13) 定义一个input组件,使其输入的值转为大写

    <!DOCTYPE html> <html> <head> <title>React JS</title> <script src=& ...

  3. VM页面中遍历枚举类

    1)自定义的枚举类如下所示: public enum BusType { MID_SMALL(1, "中小件"), FRESH(2, "生鲜"), GLOBAL ...

  4. MySQL Sleep进程

    MySQL中查询当前的连接数: mysql> show status like '%Threads_connected%'; +-------------------+-------+ | Va ...

  5. python学习笔记——爬虫学习中的重要库urllib

    1 urllib概述 1.1 urllib库中的模块类型 urllib是python内置的http请求库 其提供了如下功能: (1)error 异常处理模块 (2)parse url解析模块 (3)r ...

  6. Transparent Huge Pages

    在RHEL6中,透明大页功能是默认开启的. 开启该选项后,内核会尽可能地尝试分配大页,如果mmap区域是2mb,那么每个linux进程都会分配到2mb大小的页.如果大页不够用了(比如物理内存不够了), ...

  7. “C++的数组不支持多态”?

    先是在微博上看到了个微博和云风的评论,然后我回了“楼主对C的内存管理不了解”. 后来引发了很多人的讨论,大量的人又借机来黑C++,比如: //@Baidu-ThursdayWang:这不就c++弱爆了 ...

  8. javascript some()函数用法详解

    参数说明callback: 要对每个数组元素执行的回调函数.thisObject : 在执行回调函数时定义的this对象. 功能说明对数组中的每个元素都执行一次指定的函数(callback),直到此函 ...

  9. 章节0:MySQl学前知识储备

    一.数据库基础: 1.数据库(database):保存有组织的数据的容器(通常是一个文件或一组文件). 2.数据库管理系统(DBMS):创建和操纵数据库的软件系统. 3.表(table):某种特定类型 ...

  10. [转]同步对象Event的用法

    同步对象Event的用法  首先介绍CreateEvent是创建windows事件的意思,作用主要用在判断线程退出,线程锁定方面.  CreateEvent函数功能描述:创建或打开一个命名的或无名的事 ...