c语言监控文件变化,用delphi监控文件修改时间是否发生变化并作出自动处理
发布日期:2021-06-24 13:22:55 浏览次数:2 分类:技术文章

本文共 1199 字,大约阅读时间需要 3 分钟。

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ExtCtrls, StdCtrls;

type

TForm1 = class(TForm)

tmrl: TTimer;

mmo1: TMemo;

edtT1: TEdit;

edtT3: TEdit;

procedure tmrlTimer(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

function CovFileDate(Fd:_FileTime):TDateTime;

var

Tct:_SystemTime;

Temp:_FileTime;

begin

FileTimeToLocalFileTime(Fd,Temp);

FileTimeToSystemTime(Temp,Tct);

CovFileDate:=SystemTimeToDateTime(Tct);

end;

procedure TForm1.tmrlTimer(Sender: TObject);

const

Model='HH:mm:ss';

var

SysTime: Windows.TSystemTime;

Tp:TSearchRec;

T1,T2,T3:String;

Result:TDateTime;

begin

if FileExists('js.txt') then

begin

FindFirst('js.txt',faAnyFile,Tp);

T2:=FormatDateTime(Model,CovFileDate(Tp.FindData.ftLastWriteTime));

mmo1.Lines.Append(T2);

FindClose(Tp);

T1:=T2;

edtT1.Text:=T1;

mmo1.Lines.Append('循环中T1=T2='+T1);

if(T1<>edtT3.Text) then //T3=''

begin

mmo1.Lines.Append(T1+'变更一次!'); //

T3:=T1;

edtT3.Text:=T3;

end;

end;

end;

end.

算法:

1.定义一个timer每隔几秒自动执行一次;

2.检查文件是否存在,如果存在

3.每隔几秒就获取一次修改时间

4.和初始变量对比,如果值已经发生变化,作出相应处理,并将当前值计入新的edit中

5.将重新获取的值与edit.text值进行对比

转载地址:https://blog.csdn.net/weixin_33102135/article/details/117240934 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:android 多个复选框,列表项中的多个复选框android
下一篇:liunx c语言指定字符串替换,linux c语言字符串函数replace,indexOf,substring等的实现

发表评论

最新留言

不错!
[***.144.177.141]2024年03月31日 20时45分37秒