如何枚举某一目录下的所有文件(包含子目录),把结果写入一INI文件中.(200)

  • 主题发起人 主题发起人 abcls
  • 开始时间 开始时间
A

abcls

Unregistered / Unconfirmed
GUEST, unregistred user!
INI文件格式如下:[FileName] FilePath=文件路径 DateTime=最后修改时间
 
好做,我试试。
 
procedure TForm1.Button1Click(Sender: TObject);begin GetFiles('D:/Prj', 'D:/A.INI'); --搜索路径,保存文件名称end;Function FileTImeToDateTime(FileTime:TFileTime):TDateTime;Var sysTime:TSystemTime;begin if not FileTimeToSystemTime(FileTime,SysTime) then raise EConvertError.CreateFmt('FileTimeToSystemTime failed. Error Code %d',[GetLastError]); with SysTime do Result:=EncodeDate(wYear,wMonth,wDay)+EncodeTime(wHour,wMinute,wSecond,wMilliseconds)End;procedure TForm1.GetFiles(DirName, SaveINIFileName: String);var sr: TSearchRec; sSearch:String;begin sSearch:=DirName+'/*.*'; if FindFirst(sSearch, faAnyFile , sr) = 0 then begin repeat if (sr.Name='.') or (sr.Name='..') then continue; if (sr.Attr and faDirectory)>0 then GetFiles(DirName+'/'+Sr.Name,SaveINIFileName) else begin WritePrivateProfileString( PChar(sr.Name),'FilePath',PChar(DirName), PChar(SaveINIFileName) ); WritePrivateProfileString( PChar(sr.Name),'DateTime',PChar(Datetimetostr(FileTImeToDateTime(Sr.FindData.ftLastWriteTime))), PChar(SaveINIFileName) ); end; until FindNext(sr) <> 0; FindClose(sr); end;end;如果符合你的要求就给分。
 
procedure TSearchFileThread.SearchFile(DirName: String);Var Found: integer; SearchRec: TSearchRec;begin Found := FindFirst(DirName + '*.*',faAnyFile,searchrec); while Found = 0 do begin if ((SearchRec.Attr and faDirectory)<>0) then //directory begin if(SearchRec.Name <> '.')and(SearchRec.Name <> '..') then SearchFile(DirName + SearchRec.Name + '/') end else //file begin MyFileName := DirName + SearchRec.Name; Synchronize(DeelWithFile); end; Found := FindNext(SearchRec); end; FindClose(SearchRec);end;
 
to fanwendou请问一下:Synchronize(DeelWithFile);是什么意思?
 
我再改简单些:procedure TForm1.Button1Click(Sender: TObject);begin GetFiles('D:/Prj', 'D:/A.INI'); --搜索路径,保存文件名称end;procedure TForm1.GetFiles(DirName, SaveINIFileName: String);var sr: TSearchRec; sysTime:TSystemTime;begin if FindFirst(DirName+'/*.*', faAnyFile , sr) <> 0 then Exit; repeat if (sr.Name='.') or (sr.Name='..') then continue; if (sr.Attr and faDirectory)>0 then //如果是文件夹 GetFiles(DirName+'/'+Sr.Name,SaveINIFileName) else begin WritePrivateProfileString( PChar(sr.Name),'FilePath',PChar(DirName), PChar(SaveINIFileName) ); FileTimeToSystemTime(Sr.FindData.ftLastWriteTime,SysTime); WritePrivateProfileString( PChar(sr.Name),'DateTime',PChar(Datetimetostr( SystemTimeToDateTime(SysTime) )), PChar(SaveINIFileName) ); end; until FindNext(sr) <> 0; FindClose(sr);end;
 
to fanwendou请问一下:Synchronize(DeelWithFile);是什么意思? ///线程同步,你的代码如果没有多线程可以不用这个。
 
如何枚举某一目录下的所有文件(包含子目录),把结果写入一INI文件中. ( 积分:200, 回复:6, 阅读:39 )分类:数据库-C/S型 ????????
 
谢谢各位!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
535
import
I
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部