调用api函数,将一个目录下的所有文件名读出?(20分)

  • 主题发起人 主题发起人 liu2909432
  • 开始时间 开始时间
L

liu2909432

Unregistered / Unconfirmed
GUEST, unregistred user!
调用api函数,将一个目录下的所有文件名读出?<br>急!急!
 
不是用api函数。<br>用TSearchRec结构。自己看看帮助,或者搜索一下以前的帖子,太多了!
 
刚好手边有,贴上来供参考:<br><br>//+-------------------------------------------+<br>//| &nbsp; &nbsp; &nbsp; 得到指定路径下的所有文件列表 &nbsp; &nbsp; &nbsp; &nbsp;|<br>//+-------------------------------------------+<br>function Get_File(Path:string):TStrings; //Path就是制定的路径,得到文件的列表以TStrings返回<br>const FileAttrs = faAnyFile and (not fadirectory);<br>var<br>&nbsp; SRec: TSearchRec;<br>&nbsp; FindResult:Integer;<br>begin<br>&nbsp; &nbsp;Result:=TStringList.Create; &nbsp;<br>&nbsp; &nbsp;FindResult:=FindFirst (Path+'/'+'*.*', FileAttrs, SRec);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//^^^^^------此处可以进行文件类型的过滤<br>&nbsp; &nbsp;while FindResult= 0 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (SRec.Name &lt;&gt; '.') and (SRec.Name &lt;&gt; '..') then &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result.Add(SRec.Name);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FindResult:=FindNext(SRec);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;FindClose (SRec);<br>end;
 
简单点,<br>winexec('dir *.*&gt;1.txt')<br>再读1.txt的内容
 
谢谢我试试 !
 
procedure TForm1.MakeTree(path: string);<br>{ 子目录遍历的递归算法 }<br>var sr : TSearchRec;<br>&nbsp; &nbsp; err: integer;<br>begin<br>&nbsp; chdir(path);<br>&nbsp; err := findfirst('*.*', faAnyFile, sr);<br>&nbsp; while err = 0 do begin<br>&nbsp; &nbsp; if (sr.Name &lt;&gt; '.')and(sr.Name &lt;&gt; '..') then<br>&nbsp; &nbsp; &nbsp; if (sr.Attr and faDirectory)&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; inc(dCount);<br>&nbsp; &nbsp; &nbsp; &nbsp; MakeTree((sr.Name));<br>&nbsp; &nbsp; &nbsp; &nbsp; chdir('..');<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else inc(fCount);<br>&nbsp; &nbsp; err := findnext(sr);<br>&nbsp; end;<br>&nbsp; findclose(sr);<br>end;
 
后退
顶部