2009年10月26日月曜日

ファイルリストを取取得する。

.NetFramworkでは、ファイル名のリストを取得するだけなら
System.IO.Directory.GetFilesメソッドで簡単に取得できます。

以下、サンプル

  1. method MainForm.buttonExecGetFile_Click(sender: System.Object; e: System.EventArgs);  
  2. var  
  3.   FileList : Array of String;  
  4.   FileName : String;  
  5. begin  
  6.     
  7.   Self.listBoxResult.Items.Clear();  
  8.   
  9.   if Self.checkBoxFindSubDir.Checked then  
  10.   begin  
  11.     FileList := System.IO.Directory.GetFiles(Self.textBoxStartPath.Text,'*',System.IO.SearchOption.AllDirectories);  
  12.   end  
  13.   else  
  14.   begin  
  15.     FileList := System.IO.Directory.GetFiles(Self.textBoxStartPath.Text,'*',System.IO.SearchOption.TopDirectoryOnly);  
  16.   end;  
  17.   
  18.   For FileName in FileList do  
  19.   begin  
  20.     listBoxResult.Items.Add(FileName);   
  21.   end;  
  22. end;  

0 件のコメント: