怎样获得目录名、程序名及大小 (50分)

  • 主题发起人 主题发起人 孤岛
  • 开始时间 开始时间

孤岛

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大哥,谁能告诉我,怎样同过程序获得一个盘符下或一个目录下的<br>文件名及大小,和子目录的名称,要详细说明解释
 
procedure TForm1.Button1Click(Sender: TObject);<br><br>var<br>&nbsp; sr: TSearchRec;<br>&nbsp; FileAttrs: Integer;<br>begin<br>&nbsp; StringGrid1.RowCount := 1;<br>&nbsp; if CheckBox1.Checked then<br>&nbsp; &nbsp; FileAttrs := faReadOnly<br>&nbsp; else<br>&nbsp; &nbsp; FileAttrs := 0;<br>&nbsp; if CheckBox2.Checked then<br>&nbsp; &nbsp; FileAttrs := FileAttrs + faHidden;<br>&nbsp; if CheckBox3.Checked then<br>&nbsp; &nbsp; FileAttrs := FileAttrs + faSysFile;<br>&nbsp; if CheckBox4.Checked then<br>&nbsp; &nbsp; FileAttrs := FileAttrs + faVolumeID;<br>&nbsp; if CheckBox5.Checked then<br><br>&nbsp; &nbsp; FileAttrs := FileAttrs + faDirectory;<br>&nbsp; if CheckBox6.Checked then<br>&nbsp; &nbsp; FileAttrs := FileAttrs + faArchive;<br>&nbsp; if CheckBox7.Checked then<br><br>&nbsp; &nbsp; FileAttrs := FileAttrs + faAnyFile;<br><br>&nbsp; with StringGrid1 do<br>&nbsp; begin<br>&nbsp; &nbsp; RowCount := 0;<br><br>&nbsp; &nbsp; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then<br><br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; if (sr.Attr and FileAttrs) = sr.Attr then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; RowCount := RowCount + 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; Cells[1,RowCount-1] := sr.Name;<br>&nbsp; &nbsp; &nbsp; &nbsp; Cells[2,RowCount-1] := IntToStr(sr.Size);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; until FindNext(sr) &lt;&gt; 0;<br>&nbsp; &nbsp; &nbsp; FindClose(sr);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>-----<br>http://www.8421.org
 
这么快?!我试试!
 
不行呀?!啥意思呀!
 
procedure FileSearch(PathName:string);<br>var<br>&nbsp; F : TSearchRec;<br>&nbsp; Found : Boolean;<br>begin<br>&nbsp; ChDir(PathName);<br>&nbsp; Found := (FindFirst('*.*', faAnyFile, F) = 0);<br>&nbsp; while Found do<br>&nbsp; begin<br>&nbsp; &nbsp; if (F.Name = '.') or (F.Name = '..') then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Found := (FindNext(F) = 0);<br>&nbsp; &nbsp; &nbsp; Continue;<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; if (F.Attr and faDirectory)&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; &nbsp; &nbsp; FileSearch(F.Name);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; //插入你的代码,F.Name就是文件名,GetCurrentDir可以得到当前目录,同样可得到子目录<br>&nbsp; &nbsp; Found := (FindNext(F) = 0);<br>&nbsp; end;<br>&nbsp; FindClose(F);<br>&nbsp; ChDir('../');<br>end;<br>
 
接受答案了.
 
后退
顶部