日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#讀取文件夾中的文件操作淺析

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

創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站建設、成都做網(wǎng)站與策劃設計,鶴山網(wǎng)站建設哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設10年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:鶴山等地區(qū)。鶴山做網(wǎng)站價格咨詢:028-86922220

都是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#讀取文件夾的代碼吧,沒來得及調試,有問題自己改改吧!

 
 
 
  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#讀取文件夾之方法調用情況:

 
 
 
  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);     //調用查找文件函數(shù)  

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


網(wǎng)站標題:C#讀取文件夾中的文件操作淺析
文章網(wǎng)址:http://www.dlmjj.cn/article/cdodgee.html