文件备份 定时器(100)

H

hying95

Unregistered / Unconfirmed
GUEST, unregistred user!
我是做服装的,前些天在用电脑做结构设计时,搞了三个小时,搞出来了,通过绘图仪打出来后,不知什么原因,在后来开机时底图打不开了,非常郁闷,于是就想给这个软件加个定时备份功能,我的想法是,在程序文件夹建一个配置文件PDS.ini,写一个DLL,通过PE工具把它加到程序中,在DLL中通过读取配置文件取得时间和是否要备份。如果要备份,取得当前文件名,通过比较备份文件夹中的文件的修改时间来判断,如果时间相等,就不备份,不等就把打开的文件复制到备份文件夹。现在已经实现复制文件了,文件也进行了比较,只要备份文件夹中没有这个文件它就会自动复制,如果有了,即使修改时间不同,它也不复制,我不知问题出在哪,搞不定,对delphi只是爱好,偶尔弄弄,请富翁们帮忙。Procedure TBackupOn;var BName: string; sr: TSearchRec; FileAttrs,I_old,I_new: Integer;Begin if BackupBool=false then exit; TBackup:=Pini.ReadInteger('Program','BackupTimes',50);//备份定时器时间 BCount:=BCount+1; if BCount=TBackup then begin sLis.Clear; ssLis.Clear; BackupBool:=false; if (fileexists(ExtractFilePath(Paramstr(0))+'tmp.txt')) then ssLis.LoadFromFile(ExtractFilePath(Paramstr(0))+'tmp.txt');//为了检查问题出在哪,往磁盘上写个临时文件 BCount:=0; FileAttrs := 0; FileAttrs := FileAttrs + faAnyFile; if FindFirst(BFDir+'/*'+aName, FileAttrs, sr) = 0 then begin repeat sLis.Add(sr.Name); until FindNext(sr) <> 0; FindClose(sr); end; sLis.SaveToFile(ExtractFilePath(Paramstr(0))+'tmpFile.txt');//tmpFile.txt 文件中始终都只有一个文件不知为什么 if sLis.Count=0 then CopyFile(pchar(Filename),pchar(BFDir+'/'+delStr(timetostr(time),':')+'_'+aName),false); BName:=BFDir+'/'+sLis.Strings[sLis.count-1]; I_old:=FileOpen(BName, fmOpenRead); I_new:=FileOpen(Filename, fmOpenRead); ssLis.Add(BName+' Old '+DateTimeToStr(FileDateToDateTime(FileGetDate(I_old)))); ssLis.Add(Filename+' New '+DateTimeToStr(FileDateToDateTime(FileGetDate(I_new)))); if (I_old<0) or (I_new<0) or (I_old=I_new) then //if DateTimeToStr(FileDateToDateTime(FileGetDate(I_old)))=DateTimeToStr(FileDateToDateTime(FileGetDate(I_new))) then begin Fileclose(I_old); Fileclose(I_new); exit; end else begin CopyFile(pchar(Filename),pchar(BFDir+'/'+delStr(timetostr(time),':')+'_'+ aName),false); ssLis.SaveToFile(ExtractFilePath(Paramstr(0))+'tmp.txt');//tmp.txt文件中明明记录两个文件时间不等,上面复制文件代码好象没有执行 Fileclose(I_old); Fileclose(I_new); end; end;End;procedure pTest;var s: string; i: integer;Begin //if not(fileexists(ExtractFilePath(Paramstr(0))+'Pds.ini')) then //CallBackup; StartBackup:=Pini.ReadBool('Program','chkBackup',False); StartSave:=Pini.ReadBool('Program','chkSave',False); s:=GetFormClassName('Pattern Design System'); if StartBackup=true then begin h:=findwindow(pchar(s),nil); if h<>0 then begin aCaption:=GetFormCaption('Pattern'); Filename:=trim(after(aCaption,'m')); if pos('/',Filename)<>0 then begin I:=LastDelimiter('/',filename);//最后一个"/"位置 sDir:=copy(Filename ,1, I); aName:=copy(filename ,I+1,length(filename)-I); BFDir:=sDir+'Backup'; end; end; if sDir<>'' then begin if not DirectoryExists(BFDir) then begin if ForceDirectories(BFDir) then //创建多级目录 forceDirectories(BFDir); end; BackupBool:=true; if StartBackup=True then begin if TimerBackup<>0 then begin KillTimer(0, TimerBackup); TimerBackup := 0; end else TimerBackup:=SetTimer(0,0,1000,@TBackupOn); TBackupOn; end else begin if TimerBackup<>0 then begin KillTimer(0, TimerBackup); TimerBackup := 0; end; end; end; end;End;
 
那里有问题?
 
备份的时候是把当前的时间字符串加上当前的文件名比如我的文件名是5002.boke,那我备份文件夹里就有一个101423_5002.boke,如果设定5秒备份一次,那这个文件夹中有可能还有101923_5002.boke....查找备份文件时条件*5002.boke,然后排序,时间最新排在sLis的最后,提取这个最后文件和当前文件进行比较如果时间不等,就把当前文件复制到备份文件夹,文件名前加上时间,现在的问题是程序可以发现两个文件的时间不等,但却不备份不知问题出在哪,在sLis中始终只有一个文件
 
自己解决了
 
如有哪位富翁把我另一个问题解决了,这100分一起给他
 
代码太高深 看了几句看不下去了。
 
不过可以提醒你一句 如果你的结构设计软件是以独占方式打开文档的 你怎么可能复制?
 
to 地质灾害 看下下面的问题如果可以解决一共200分全给你http://www.delphibbs.com/delphibbs/dispq.asp?lid=3986748
 
顶部