自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#讀取文件夾中的文件操作淺析

開發(fā) 后端
C#讀取文件夾中的文件操作是怎么樣子的呢?那么本文就向你介紹這方面的內(nèi)容,希望對你有所幫助。

C#讀取文件夾的操作是如何進行的呢?首先讓我們來看啊可能:讀出一個文件夾中的所有文件(文件數(shù)從0個到N多不定).沒有文件返回假.

都是ascii碼文件.

讀每個文件的前一部分至出現(xiàn)***個 /s./s/r 為止.

讀出來放后放至string[] filetsr中. 

  1. strFiles = Directory.GetFiles(@"c:\Import");   
  2. foreach(string strFile in strFiles)   
  3. {   
  4. File.Move(strFile,strFile.Replace("Import","Rubbish_Files"));   
  5.  
  6. //上面這句換為你的C#讀取文件夾處理。   
  7.  

試試看C#讀取文件夾的代碼吧,沒來得及調(diào)試,有問題自己改改吧!

  1. using System;   
  2. using System.IO;   
  3.  
  4. class Test   
  5. {   
  6. public static void Main()   
  7. {   
  8. try   
  9. {   
  10. // Only get files that begin with the letter "c."   
  11. int i=0;   
  12. string[] dirs = Directory.GetFiles(@"c:\", "c*");   
  13. Console.WriteLine("The number of files starting with c is {0}.", dirs.Length);   
  14. string[] filetsr=new String[dirs.Length];   
  15. foreach (string dir in dirs)   
  16. {   
  17. FileStream fs = new FileStream(dir,FileMode.Open);   
  18. byte[] readBuf=new byte[fs.Length];   
  19. syncF.Read(readBuf,0,fs.Length);   
  20.  
  21. data = Encoding.ASCII.GetString(readBuf);   
  22. if (data.IndexOf("/s./s/r") > -1)   
  23. {   
  24. i++;   
  25. filestr[i]=Microsoft.Basic.Left(data.IndexOf("/s./s/r") -1)   
  26. }   
  27.  
  28. }   
  29. }   
  30. catch (Exception e)   
  31. {   
  32. Console.WriteLine("The process failed: {0}", e.ToString());   
  33. }   
  34. }   

C#中遍歷文件夾目錄的問題

C#讀取文件夾之遞歸實現(xiàn)查找目錄下的所有子目錄和文件

  1. public   void   FindFile(string   dir)   //參數(shù)為指定的目錄  
  2. {       
  3. //C#讀取文件夾在指定目錄及子目錄下查找文件,在listBox1中列出子目錄及文件  
  4. DirectoryInfo   Dir=new   DirectoryInfo(dir);  
  5. try 
  6. {  
  7.       foreach(DirectoryInfo   d   in   Dir.GetDirectories())//查找子目錄     
  8. {  
  9. FindFile(Dir+d.ToString()+"\\");  
  10. listBox1.Items.Add(Dir+d.ToString()+"\\");  //listBox1中填加目錄名  
  11. }  
  12.       foreach(FileInfo   f   in   Dir.GetFiles("*.*")) //查找文件  
  13. {  
  14. listBox1.Items.Add(Dir+f.ToString());  //listBox1中填加文件名  
  15. }  
  16. }  
  17. catch(Exception   e)  
  18. {  
  19. MessageBox.Show(e.Message);  
  20. }  
  21.  

C#讀取文件夾之方法調(diào)用情況:

  1. private   void   button1_Click(object   sender,   System.EventArgs   e)  
  2. {  
  3. string   currentdir="F:\\myprogram\\C#\\FileSearch";     //搜索的目錄  
  4. if(currentdir[currentdir.Length-1]!='\\')   //非根目錄  
  5. currentdir+="\\";     
  6. FindFile(currentdir);     //調(diào)用查找文件函數(shù)  

C#讀取文件夾中的文件的基本的情況就向你介紹到這里,希望對你學習C#讀取文件夾有所幫助。

【編輯推薦】

  1. C#賦值運算符之復合賦值運算符
  2. C#讀取XML文檔實例淺析
  3. C#讀取XML文檔的實現(xiàn)淺析
  4. C#讀取XML節(jié)點內(nèi)容方法實例簡析
  5. C#讀取XML文檔使用XMLTextReader類淺析
責任編輯:仲衡 來源: 百度空間
相關推薦

2009-08-31 10:56:54

C#創(chuàng)建文件夾

2009-08-31 12:31:45

C#創(chuàng)建文件夾

2009-08-17 07:55:00

C#文件操作

2009-08-12 17:27:11

C#讀取文件

2009-08-13 09:16:57

C#讀取配置文件

2009-08-31 18:38:59

C#寫文件

2011-05-23 17:00:29

2009-09-02 19:08:03

C#實現(xiàn)讀取文本文件

2009-08-12 18:06:53

C#讀取二進制文件

2009-08-12 17:12:51

C#讀取文件夾

2020-09-23 08:53:48

父文件夾模塊Python

2009-08-18 16:14:05

C# 操作Excel

2009-08-31 12:56:36

C#創(chuàng)建文件夾

2009-09-02 19:22:03

C#遞歸

2009-08-18 16:42:49

C# 操作XML

2009-08-19 15:55:42

C#操作Access

2023-03-28 15:19:37

文件列表scandir函數(shù)

2009-09-01 14:45:45

C#創(chuàng)建Excel文件

2009-08-19 13:25:53

C#操作注冊表

2009-08-19 17:44:15

C#操作文本文件
點贊
收藏

51CTO技術棧公眾號