📄 folderlastmodifythreadunit.pas
字号:
unit FolderLastModifyThreadUnit;
interface
uses
Classes, Windows, SysUtils;
type
TFolderLastModifyThread = class(TThread)
private
{ Private declarations }
sFolderName:String;
dirNumber:integer;
fileNumber:integer;
procedure GetFolserLastModifyDone(sDirName:String; var fileSum, folderSum:integer);
procedure GetFolserLastModify;
protected
procedure Execute; override;
public
constructor Create(_sFolderName:String);
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TFolderLastModifyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TFolderLastModifyThread }
uses
FileTestUnit, TestFunctionUnit;
constructor TFolderLastModifyThread.Create(_sFolderName:String);
begin
sFolderName:=_sFolderName;
dirNumber:=0;
fileNumber:=0;
inherited Create(True);
end;
procedure TFolderLastModifyThread.GetFolserLastModifyDone(sDirName:String; var fileSum, folderSum:integer);
var
hFindfile:Cardinal;
tfile:String;
sCurDir:String[255];
//FindFileData:WIN32_FIND_DATA;
FindFileData: TWin32FindData;
getstr:String;
begin
//先保存当前目录
sCurDir:=GetCurrentDir;
ChDir(sDirName);
hFindfile:=FindFirstFile('*.*',FindFileData);
if hFindFile<>INVALID_HANDLE_VALUE then
begin
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue;
//if (FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY) or (FindFileData.dwFileAttributes=48) then
if FindFileData.dwFileAttributes and faDirectory = faDirectory then
begin
folderSum:=folderSum+1;
FileTestForm.ListBox1.Items.Add(tfile+'-->'+IntToStr(FindFileData.dwFileAttributes));
if sDirName[Length(sDirName)]<>'\' then
GetFolserLastModifyDone(sDirName+'\'+tfile,fileSum, folderSum)
else
GetFolserLastModifyDone(sDirName+tfile, fileSum, folderSum);
end
else
begin
fileSum:=fileSum+1;
getStr:=IntToStr(FindFileData.dwFileAttributes)+','+DateTimeToStr(now)+','+tfile+' 的最近一次修改时间为:'+DateTimeToStr(GetFileLastModifyTime(sDirName+'\'+tfile));
FileTestForm.ListBox1.Items.Add(getStr);
end;
until FindNextFile(hFindFile,FindFileData)=false;
Windows.FindClose(hFindFile);
end
else
begin
ChDir(sCurDir);
exit;
end;
//回到原来的目录下
ChDir(sCurDir);
end;
procedure TFolderLastModifyThread.GetFolserLastModify;
begin
GetFolserLastModifyDone(sFolderName,fileNumber,dirNumber);
FileTestForm.ListBox1.Items.Add('==========共有文件夹:'+IntToStr(DirNumber)+'个');
FileTestForm.ListBox1.Items.Add('==========共有文件:'+IntToStr(fileNumber)+'个');
end;
procedure TFolderLastModifyThread.Execute;
begin
{ Place thread code here }
FreeOnTerminate:=True;
synchronize(GetFolserLastModify);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -