原文:C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名

  1. 本文也收集了目前最为常用的C#经典操作文件的方法,具体内容如下:C#追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件、指定文件夹下面的所有内容copy到目标文件夹下面、指定文件夹下面的所有内容Detele、读取文本文件、获取文件列表、读取日志文件、写入日志文件、创建HTML 文件、CreateDirectory方法的使用.修改文件或文件夹名称等方法使用.....
  2. C#追加文件
  3.     StreamWriter sw = File.AppendText(Server.MapPath(".")+"\\myText.txt");
  4.     sw.WriteLine("追逐理想");
  5.     sw.WriteLine("kzlll");
  6.     sw.WriteLine(".NET笔记");
  7.     sw.Flush();
  8.     sw.Close();
  9. C#拷贝文件
  10.     string OrignFile,NewFile;
  11.     OrignFile = Server.MapPath(".")+"\\myText.txt";
  12.     NewFile = Server.MapPath(".")+"\\myTextCopy.txt";
  13.     File.Copy(OrignFile,NewFile,true);
  14. C#删除文件
  15.     string delFile = Server.MapPath(".")+"\\myTextCopy.txt";
  16.     File.Delete(delFile);
  17. C#移动文件
  18.     string OrignFile,NewFile;
  19.     OrignFile = Server.MapPath(".")+"\\myText.txt";
  20.     NewFile = Server.MapPath(".")+"\\myTextCopy.txt";
  21.     File.Move(OrignFile,NewFile);
  22. C#创建目录
  23. // 创建目录c:\sixAge
  24.     DirectoryInfo d=Directory.CreateDirectory("c:\\sixAge");
  25. // d1指向c:\sixAge\sixAge1
  26.     DirectoryInfo d1=d.CreateSubdirectory("sixAge1");
  27. // d2指向c:\sixAge\sixAge1\sixAge1_1
  28.     DirectoryInfo d2=d1.CreateSubdirectory("sixAge1_1");
  29. // 将当前目录设为c:\sixAge
  30.     Directory.SetCurrentDirectory("c:\\sixAge");
  31. // 创建目录c:\sixAge\sixAge2
  32.     Directory.CreateDirectory("sixAge2");
  33. // 创建目录c:\sixAge\sixAge2\sixAge2_1
  34.     Directory.CreateDirectory("sixAge2\\sixAge2_1");
  35. 递归删除文件夹及文件
  36. 〈%@PageLanguage=C#%〉
  37. 〈%@Importnamespace="System.IO"%〉
  38. Scriptrunat=server
  39. publicvoidDeleteFolder(stringdir)
  40. {
  41. if(Directory.Exists(dir))//如果
  42. 存在这个文件夹删除之
  43. {
  44. foreach(stringdinDirectory.
  45. GetFileSystemEntries(dir))
  46. {
  47. if(File.Exists(d))
  48. File.Delete(d);//直接删除其中的文件
  49. else
  50. DeleteFolder(d);//递归删除子文件夹
  51. }
  52. Directory.Delete(dir);//删除已空文件夹
  53. Response.Write(dir+"文件夹删除成功");
  54. }
  55. else
  56. Response.Write(dir+"该文件夹不存在");//如果
  57. 文件夹不存在则提示
  58. }
  59. protectedvoidPage_Load(Object
  60. sender,EventArgse)
  61. {
  62. stringDir="D:\\gbook\\11";
  63. DeleteFolder(Dir);//调用函数删除文件夹
  64. }
  65.  
  66. //========================================
  67. //实现一个静态方法将指定文件夹下面的所有内容copy到目标文件夹下面
  68. //如果目标文件夹为只读属性就会报错。
  69. //========================================
  70. publicstaticvoidCopyDir(stringsrcPath,
  71. stringaimPath)
  72. {
  73. try
  74. {
  75. //检查目标目录是否以目录分割字
  76. 符结束如果不是则添加之
  77. if(aimPath[aimPath.Length-1]!= Path.DirectorySeparatorChar)
  78. aimPath+=Path.DirectorySeparatorChar;
  79. //判断目标目录是否存在如果不存在则新建之
  80. if(!Directory.Exists(aimPath))Directory.CreateDirectory(aimPath);
  81. //得到源目录的文件列表,
  82. 该里面是包含文件以及目录路径的一个数组
  83. //如果你指向copy目标文件下面的文件
  84. 而不包含目录请使用下面的方法
  85. //string[]fileList=Directory.GetFiles(srcPath);
  86. string[]fileList=Directory.GetFileSystemEntries(srcPath);
  87. //遍历所有的文件和目录
  88. foreach(stringfileinfileList)
  89. {
  90. //先当作目录处理如果存在这个
  91. 目录就递归Copy该目录下面的文件
  92. if(Directory.Exists(file))
  93. CopyDir(file,aimPath+Path.GetFileName(file));
  94. //否则直接Copy文件
  95. else
  96. File.Copy(file,aimPath+Path.GetFileName(file),true);
  97. }
  98. }
  99. catch(Exceptione)
  100. {
  101. MessageBox.Show(e.ToString());
  102. }
  103. }
  104. //========================================
  105. //实现一个静态方法将指定文件夹下面的所有内容Detele
  106. //测试的时候要小心操作,删除之后无法恢复。
  107. //========================================
  108. publicstaticvoidDeleteDir(stringaimPath)
  109. {
  110. try
  111. {
  112. //检查目标目录是否以目录分割字
  113. 符结束如果不是则添加之
  114. if(aimPath[aimPath.Length-1]!=
  115. Path.DirectorySeparatorChar)
  116. aimPath+=Path.DirectorySeparatorChar;
  117. //得到源目录的文件列表,
  118. 该里面是包含文件以及目录路径的一个数组
  119. //如果你指向Delete目标文件下面的
  120. 文件而不包含目录请使用下面的方法
  121. //string[]fileList=
  122. Directory.GetFiles(aimPath);
  123. string[]fileList=
  124. Directory.GetFileSystemEntries(aimPath);
  125. //遍历所有的文件和目录
  126. foreach(stringfileinfileList)
  127. {
  128. //先当作目录处理如果存在这个
  129. 目录就递归Delete该目录下面的文件
  130. if(Directory.Exists(file))
  131. {
  132. DeleteDir(aimPath+Path.GetFileName(file));
  133. }
  134. //否则直接Delete文件
  135. else
  136. {
  137. File.Delete(aimPath+Path.GetFileName(file));
  138. }
  139. }
  140. //删除文件夹
  141. System.IO.Directory.Delete(aimPath,true);
  142. }
  143. catch(Exceptione)
  144. {
  145. MessageBox.Show(e.ToString());
  146. }
  147. }
  148. C# <wbr>文件操作(全部) <wbr>追加、拷贝、删除、移动文件、创建目录 <wbr>修改文件名、文件夹名
  149. 需要引用命名空间:
  150. usingSystem.IO;
  151. ///〈summary〉
  152. ///拷贝文件夹(包括子文件夹)到指定文件夹下,
  153. 源文件夹和目标文件夹均需绝对路径.
  154. 格式:CopyFolder(源文件夹,目标文件夹);
  155. ///〈/summary〉
  156. ///〈paramname="strFromPath"〉〈/param〉
  157. ///〈paramname="strToPath"〉〈/param〉
  158.  
  159. //----------------------------------------
  160. C# <wbr>文件操作(全部) <wbr>追加、拷贝、删除、移动文件、创建目录 <wbr>修改文件名、文件夹名
  161.  
  162. //----------------------------------------
  163. publicstaticvoidCopyFolder(stringstrFromPath,
  164. stringstrToPath)
  165. {
  166. //如果源文件夹不存在,则创建
  167. if(!Directory.Exists(strFromPath))
  168. {
  169. Directory.CreateDirectory(strFromPath);
  170. }
  171.  
  172. //取得要拷贝的文件夹名
  173. stringstrFolderName=strFromPath.Substring(
  174. strFromPath.LastIndexOf("\")+1,strFromPath.
  175. Length-strFromPath.LastIndexOf("\")-1);
  176.  
  177. //如果目标文件夹中没有源文件夹则在目标文件夹中创建源文件夹
  178. if(!Directory.Exists(strToPath+"\"
  179. +strFolderName))
  180. {
  181. Directory.CreateDirectory(strToPath+"\"
  182. +strFolderName);
  183. }
  184. //创建数组保存源文件夹下的文件名
  185. string[]strFiles=Directory.GetFiles(strFromPath);
  186.  
  187. //循环拷贝文件
  188. for(inti=0;istrFiles.Length;i++)
  189. {
  190. //取得拷贝的文件名,只取文件名,地址截掉。
  191. stringstrFileName=strFiles[i].Substring(
  192. strFiles[i].LastIndexOf("\")+1,
  193. strFiles[i].Length-strFiles[i].
  194. LastIndexOf("\")-1);
  195. //开始拷贝文件,true表示覆盖同名文件
  196. File.Copy(strFiles[i],strToPath+"\"
  197. +strFolderName+"\"+strFileName,true);
  198. }
  199.  
  200. //创建DirectoryInfo实例
  201. DirectoryInfodirInfo=newDirectoryInfo(
  202. strFromPath);
  203. //取得源文件夹下的所有子文件夹名称
  204. DirectoryInfo[]ZiPath=dirInfo.GetDirectories();
  205. for(intj=0;jZiPath.Length;j++)
  206. {
  207. //获取所有子文件夹名
  208. stringstrZiPath=strFromPath+"\"+
  209. ZiPath[j].ToString();
  210. //把得到的子文件夹当成新的源文件夹,
  211. 从头开始新一轮的拷贝
  212. CopyFolder(strZiPath,strToPath+"\"+
  213. strFolderName);
  214. }
  215. }
  216.  
  217. C#文件操作:读取文本文件
  218. 1/// 〈summary〉
  219. 2/// 读取文本文件
  220. 3/// 〈/summary〉
  221. 4private void ReadFromTxtFile()
  222. 5{
  223. 6 if(filePath.PostedFile.
  224. FileName != "")
  225. 7 {
  226. 8 txtFilePath =
  227. filePath.PostedFile.FileName;
  228. 9 fileExtName =
  229. txtFilePath.Substring(txtFilePath.
  230. LastIndexOf(".")+1,3);
  231. 10
  232. 11 if(fileExtName !="txt" &&
  233. fileExtName != "TXT")
  234. 12 {
  235. 13 Response.Write("请选择文本文件");
  236. 14 }
  237. 15 else
  238. 16 {
  239. 17 StreamReader fileStream =
  240. new StreamReader(txtFilePath,Encoding.Default);
  241. 18 txtContent.Text = fileStream.ReadToEnd();
  242. 19 fileStream.Close();
  243. 20 }
  244. 21 }
  245. 22 }
  246. C#文件操作:获取文件列表
  247. 1/// 〈summary〉
  248. 2/// 获取文件列表
  249. 3/// 〈/summary〉
  250. 4private void GetFileList()
  251. 5{
  252. 6 string strCurDir,FileName,FileExt;
  253. 7
  254. 8 ///文件大小
  255. 9 long FileSize;
  256. 10
  257. 11 ///最后修改时间;
  258. 12 DateTime FileModify;
  259. 13
  260. 14 ///初始化
  261. 15 if(!IsPostBack)
  262. 16 {
  263. 17 ///初始化时,默认为当前页面所在的目录
  264. 18 strCurDir = Server.MapPath(".");
  265. 19 lblCurDir.Text = strCurDir;
  266. 20 txtCurDir.Text = strCurDir;
  267. 21 }
  268. 22 else
  269. 23 {
  270. 24 strCurDir = txtCurDir.Text;
  271. 25 txtCurDir.Text = strCurDir;
  272. 26 lblCurDir.Text = strCurDir;
  273. 27 }
  274. 28 FileInfo fi;
  275. 29 DirectoryInfo dir;
  276. 30 TableCell td;
  277. 31 TableRow tr;
  278. 32 tr = new TableRow();
  279. 33
  280. 34 ///动态添加单元格内容
  281. 35 td = new TableCell();
  282. 36 td.Controls.Add(new LiteralControl(
  283. "文件名"));
  284. 37 tr.Cells.Add(td);
  285. 38 td = new TableCell();
  286. 39 td.Controls.Add(new LiteralControl( "文件类型"));
  287. 40 tr.Cells.Add(td);
  288. 41 td = new TableCell();
  289. 42 td.Controls.Add(new LiteralControl( "文件大小"));
  290. 43 tr.Cells.Add(td);
  291. 44 td = new TableCell();
  292. 45 td.Controls.Add(new LiteralControl( "最后修改时间"));
  293. 46 tr.Cells.Add(td);
  294. 47
  295. 48 tableDirInfo.Rows.Add(tr);
  296. 49
  297. 50 ///针对当前目录建立目录引用对象
  298. 51 DirectoryInfo dirInfo = new DirectoryInfo( txtCurDir.Text);
  299. 52
  300. 53 ///循环判断当前目录下的文件和目录
  301. 54 foreach(FileSystemInfo fsi in dirInfo.
  302. GetFileSystemInfos())
  303. 55 {
  304. 56 FileName = "";
  305. 57 FileExt = "";
  306. 58 FileSize = 0;
  307. 59
  308. 60 ///如果是文件
  309. 61 if(fsi is FileInfo)
  310. 62 {
  311. 63 fi = (FileInfo)fsi;
  312. 64
  313. 65 ///取得文件名
  314. 66 FileName = fi.Name;
  315. 67
  316. 68 ///取得文件的扩展名
  317. 69 FileExt = fi.Extension;
  318. 70
  319. 71 ///取得文件的大小
  320. 72 FileSize = fi.Length;
  321. 73
  322. 74 ///取得文件的最后修改时间
  323. 75 FileModify = fi.LastWriteTime;
  324. 76 }
  325. 77
  326. 78 ///否则是目录
  327. 79 else
  328. 80 {
  329. 81 dir = (DirectoryInfo)fsi;
  330. 82
  331. 83 ///取得目录名
  332. 84 FileName = dir.Name;
  333. 85
  334. 86 ///取得目录的最后修改时间
  335. 87 FileModify = dir.LastWriteTime;
  336. 88
  337. 89 ///设置文件的扩展名为"文件夹"
  338. 90 FileExt = "文件夹";
  339. 91 }
  340. 92
  341. 93 ///动态添加表格内容
  342. 94 tr = new TableRow();
  343. 95 td = new TableCell();
  344. 96 td.Controls.Add(new LiteralControl( FileName));
  345. 97 tr.Cells.Add(td);
  346. 98 td = new TableCell();
  347. 99 td.Controls.Add(new LiteralControl( FileExt));
  348. 100 tr.Cells.Add(td);
  349. 101 td = new TableCell();
  350. 102 td.Controls.Add(new LiteralControl( FileSize.ToString()+"字节"));
  351. 103 tr.Cells.Add(td);
  352. 104 td = new TableCell();
  353. 105 td.Controls.Add(new LiteralControl( FileModify.ToString("yyyy-mm-dd hh:mm:ss")));
  354. 106 tr.Cells.Add(td);
  355. 107 tableDirInfo.Rows.Add(tr);
  356. 108 }
  357. 109}
  358. C#文件操作:读取日志文件
  359. 1/// 〈summary〉
  360. 2/// 读取日志文件
  361. 3/// 〈/summary〉
  362. 4private void ReadLogFile()
  363. 5{
  364. 6 ///从指定的目录以打 开或者创建的形式读取日志文件
  365. 7 FileStream fs =
  366. new FileStream(Server.MapPath("upedFile"
  367. )+"\\logfile.txt", FileMode.OpenOrCreate,
  368. FileAccess.Read);
  369. 8
  370. 9 ///定义输出字符串
  371. 10 StringBuilder output = new StringBuilder();
  372. 11
  373. 12 ///初始化该字符串的长度为0
  374. 13 output.Length = 0;
  375. 14
  376. 15 ///为上面创建的文件流创建读取数据流
  377. 16 StreamReader read = new StreamReader(fs);
  378. 17
  379. 18 ///设置当前流的起始位置为文件流的起始点
  380. 19 read.BaseStream.Seek(0, SeekOrigin.Begin);
  381. 20
  382. 21 ///读取文件
  383. 22 while (read.Peek() -1)
  384. 23 {
  385. 24 ///取文件的一行内容并换行
  386. 25 output.Append(read.ReadLine() + "\n");
  387. 26 }
  388. 27
  389. 28 ///关闭释放读数据流
  390. 29 read.Close();
  391. 30
  392. 31 ///返回读到的日志文件内容
  393. 32 return output.ToString();
  394. }
  395.  
  396. C#文件操作:写入日志文件
  397. 1/// 〈summary〉
  398. 2/// 写入日志文件
  399. 3/// 〈/summary〉
  400. 4/// 〈param name="input"〉〈/param〉
  401. 5private void WriteLogFile(string input)
  402. 6{
  403. 7 ///指定日志文件的目录
  404. 8 string fname = Server.MapPath("upedFile") + "\\logfile.txt";
  405. 9 ///定义文件信息对象
  406. 10 FileInfo finfo = new FileInfo(fname);
  407. 11
  408. 12 ///判断文件是否存在以及是否大于2K
  409. 13 if ( finfo.Exists && finfo.Length 2048 )
  410. 14 {
  411. 15 ///删除该文件
  412. 16 finfo.Delete();
  413. 17 }
  414. 18 ///创建只写文件流
  415. 19 using(FileStream fs = finfo.OpenWrite())
  416. 20 {
  417. 21 ///根据上面创建的文件流创建写数据流
  418. 22 StreamWriter w = new StreamWriter(fs);
  419. 23
  420. 24 ///设置写数据流的起始位置为文件流的末尾
  421. 25 w.BaseStream.Seek(0, SeekOrigin.End);
  422. 26
  423. 27 ///写入“Log Entry : ”
  424. 28 w.Write("\nLog Entry : ");
  425. 29
  426. 30 ///写入当前系统时间并换行
  427. 31 w.Write("{0} {1} \r\n", DateTime.Now.
  428. ToLongTimeString(),
  429. 32 DateTime.Now.ToLongDateString());
  430. 33
  431. 34 ///写入日志内容并换行
  432. 35 w.Write(input + "\n");
  433. 36
  434. 37 ///写入----------------“并换行
  435. 38 w.Write("------------------\n");
  436. 39
  437. 40 ///清空缓冲区内容,并把缓冲区内容写入基础流
  438. 41 w.Flush();
  439. 42
  440. 43 ///关闭写数据流
  441. 44 w.Close();
  442. 45 }
  443. 46}
  444. C#文件操作:创建HTML文件
  445. 1/// 〈summary〉
  446. 2/// 创建HTML文件
  447. 3/// 〈/summary〉
  448. 4private void CreateHtmlFile()
  449. 5{
  450. 6 ///定义和html标记数目一致的数组
  451. 7 string[] newContent = new string[5];
  452. 8 StringBuilder strhtml =
  453. new StringBuilder();
  454. 9 try
  455. 10 {
  456. 11 ///创建StreamReader对象
  457. 12 using (StreamReader sr =
  458. new StreamReader(Server.MapPath("createHTML") + "\\template.html"))
  459. 13 {
  460. 14 String oneline;
  461. 15
  462. 16 ///读取指定的HTML文件模板
  463. 17 while ((oneline = sr.ReadLine())
  464. != null)
  465. 18 {
  466. 19 strhtml.Append(oneline);
  467. 20 }
  468. 21 sr.Close();
  469. 22 }
  470. 23 }
  471. 24 catch(Exception err)
  472. 25 {
  473. 26 ///输出异常信息
  474. 27 Response.Write(err.ToString());
  475. 28 }
  476. 29 ///为标记数组赋值
  477. 30 newContent[0] = txtTitle.Text;//标题
  478. 31 newContent[1] = "BackColor='#cccfff'";//背景色
  479. 32 newContent[2] = "#ff0000";//字体颜色
  480. 33 newContent[3] = "100px";//字体大小
  481. 34 newContent[4] = txtContent.Text;//主要内容
  482. 35
  483. 36 ///根据上面新的内容生成html文件
  484. 37 try
  485. 38 {
  486. 39 ///指定要生成的HTML文件
  487. 40 string fname = Server.MapPath( "createHTML") +"\" + DateTime.Now.ToString(
  488. "yyyymmddhhmmss") + ".html";
  489. 41
  490. 42 ///替换html模版文件里的标记为新的内容
  491. 43 for(int i=0;i 〈 5;i++)
  492. 44 {
  493. 45 strhtml.Replace("$htmlkey["+i+"]",newContent[i]);
  494. 46 }
  495. 47 ///创建文件信息对象
  496. 48 FileInfo finfo = new FileInfo(fname);
  497. 49
  498. 50 ///以打开或者写入的形式创建文件流
  499. 51 using(FileStream fs = finfo.OpenWrite())
  500. 52 {
  501. 53 ///根据上面创建的文件流创建写数据流
  502. 54 StreamWriter sw = new StreamWriter(fs,System.
  503. Text.Encoding.GetEncoding("GB2312"));
  504. 55
  505. 56 ///把新的内容写到创建的HTML页面中
  506. 57 sw.WriteLine(strhtml);
  507. 58 sw.Flush();
  508. 59 sw.Close();
  509. 60 }
  510. 61
  511. 62 ///设置超级链接的属性
  512. 63 hyCreateFile.Text = DateTime.Now.ToString("yyyymmddhhmmss")+".html";
  513. 64 hyCreateFile.NavigateUrl = "
  514. createHTML/"+DateTime.Now.ToString(" yyyymmddhhmmss")+".html";65 }
  515. 66 catch(Exception err)
  516. 67 {
  517. 68 Response.Write (err.ToString());
  518. 69 }
  519. }
  520. CreateDirectory方法的使用
  521. using System;
  522. using System.IO;
  523.  
  524. class Test
  525. {
  526.   public static void Main()
  527.   {
  528.     // Specify the directory you want to manipulate.
  529.     string path = @"c:\MyDir";
  530.  
  531.     try
  532.     {
  533.       // Determine whether the directory exists.
  534.       if (Directory.Exists(path))
  535.       {
  536.         Console.WriteLine("That path exists already.");
  537.         return;
  538.       }
  539.  
  540.       // Try to create the directory.
  541.       DirectoryInfo di = Directory.CreateDirectory(path);
  542.       Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(path));
  543.  
  544.       // Delete the directory.
  545.       di.Delete();
  546.       Console.WriteLine("The directory was deleted successfully.");
  547.     }
  548.     catch (Exception e)
  549.     {
  550.       Console.WriteLine("The process failed: {0}", e.ToString());
  551.     }
  552.     finally {}
  553.   }
  554. }
  555.  
  556. C#修改文件或文件夹名称
  557. 参考文档,做了个demo,move()方法其实就是重命名的;另外,使用DirectoryInfo中的moveto也是可以实现的。
  558. sourceCode:
  559. string srcFileName = @"D:/a.txt";
  560. string destFileName = @"D:/b.txt";
  561. string srcFolderPath = @"D:/1";
  562. string destFolderPath = @"D:/6";
  563.  
  564. //方法一
  565. if (System.IO.File.Exists(srcFileName))
  566. {
  567. System.IO.File.Move(srcFileName, destFileName);
  568. }
  569. if (System.IO.Directory.Exists(srcFolderPath))
  570. {
  571. System.IO.Directory.Move(srcFolderPath, destFolderPath);
  572. }
  573.  
  574. //方法二
  575. if (System.IO.File.Exists(srcFileName))
  576. {
  577. System.IO.FileInfo file = new System.IO.FileInfo(srcFileName);
  578. file.MoveTo(destFileName);
  579. }
  580. if (System.IO.Directory.Exists(srcFolderPath))
  581. {
  582. System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(srcFolderPath);
  583. folder.MoveTo(destFolderPath);
  584. }

  转自http://blog.sina.com.cn/s/blog_5f82a10601019qlv.html

C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名的更多相关文章

  1. iOS——文件操作NSFileManager (创建、删除,复制,粘贴)

    iOS——文件操作NSFileManager (创建.删除,复制,粘贴)       iOS的沙盒机制,应用只能访问自己应用目录下的文件.iOS不像android,没有SD卡概念,不能直接访问图像.视 ...

  2. C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!

    https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...

  3. git操作之git clean删除一些没有git add的文件

    删除 一些 没有 git add 的 文件: git clean 参数 -n 显示 将要 删除的 文件 和  目录 -f 删除 文件,-df 删除 文件 和 目录

  4. Python文件操作大全,随机删除文件夹内的任意文件

     在读文件的时候往往需要遍历文件夹,python的os.path包含了很多文件.文件夹操作的方法: os.path.abspath(path) #返回绝对路径os.path.basename(path ...

  5. python 文件操作,os.path.walk()的回调函数打印文件名

    #coding=utf-8 import osdef find_file(arg,dirname,files):    #for i in arg:        #print i for file ...

  6. 文件操作之增删改查3---文件的修改,f.replace(),在linux里的一些应用sed,with语句方法来打开一个或多个文件避免忘记关闭,python一行写的太长,怎么编写多行的规范

    f.replace()with open("xxx","r",encoding="utf-8") as f: 想修改文件中间的数据,有两个办 ...

  7. python 文件操作 练习:把一个目录下的所有文件名,打印一下,不要包含后缀名

    #coding=utf-8 import osos.chdir('d:\\test2')file_list=os.listdir('.')print "file_list:",fi ...

  8. Java文件操作源码大全

    Java文件操作源码大全 1.创建文件夹 52.创建文件 53.删除文件 54.删除文件夹 65.删除一个文件下夹所有的文件夹 76.清空文件夹 87.读取文件 88.写入文件 99.写入随机文件 9 ...

  9. 【转载】C#工具类:实现文件操作File的工具类

    在应用程序的开发中,文件操作的使用基本上是必不可少的,FileStream类.StreamWriter类.Directory类.DirectoryInfo类等都是文件操作中时常涉及到的类,我们可以通过 ...

随机推荐

  1. UVA 322 ships (POJ 1138)

    题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  2. SQL窗体函數一例

    需求: MSSQL,列出服務實例中全部數據庫的例如以下信息: 數據庫ID.數據庫名.創建日期.數據文件類型.數據文件大小.數據庫總大小.文件所在路徑. 寫法(後面的百分比為所花時間占比): -- 连接 ...

  3. spring mvc +cookie+拦截器功能 实现系统自动登陆

    先看看我遇到的问题: @ResponseBody @RequestMapping("/logout") public Json logout(HttpSession session ...

  4. Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary lo

    mysql> show slave status\G *************************** 1. row ***************************         ...

  5. shell oracle

    #!/bin/sh traffic= rm -rf test.txt data=`sqlplus -S anoscfg/anoscfg <<EOF spool test.txt set f ...

  6. java输出空心菱形

    package com.zsh; import java.util.Scanner; public class Test08 { public static void main(String[] ar ...

  7. 积累的VC编程小技巧之滚动条

    1.设置滚动条的滚动大小 创建一个基于CScrollview的SDI Project(在第6步中选CScrollview) 若你已创建了,这步可以省略. 然后: 改为如 void CTestView: ...

  8. Lucene.Net 2.3.1开发介绍 —— 二、分词(四)

    原文:Lucene.Net 2.3.1开发介绍 -- 二.分词(四) 2.1.2 可以使用的内置分词 简单的分词方式并不能满足需求.前文说过Lucene.Net内置分词中StandardAnalyze ...

  9. [Java][Android][Process] ProcessBuilder与Runtime差别

    在Android中想要进行Ping,在不Root机器的情况下似乎还仅仅能进行底层命调用才干实现. 由于在Java中要进行ICMP包发送须要Root权限. 于是仅仅能通过创建进程来攻克了.创建进程在Ja ...

  10. Nancy.Host的Web应用

    Nancy.Host实现脱离iis的Web应用 本篇将介绍如何使用Nancy.Host实现脱离iis的Web应用,在开源任务管理平台TaskManagerV2.0代码里面已经使用了Nancy.Host ...