创建删除文件的功能实现(求助!)
//--------------------退出程序时触发--------------------procedure TMainForm.FormDestroy(Sender: TObject);var sr:TSearchRec; // FileName: string; // i: Integer;beginif FindFirst(m_Client+'*.log',faAnyFile,sr)=0 then \\m_Client 是当面目录 begin repeat winexec('cmd.exe /c taskkill /f /t /im yuancheng.exe',sw_hide); \\关闭远程连接程序 DeleteFile(m_Client+sr.name); \\删除日志文件 DeleteFile(PChar(m_Client)+'!php.txt'); \\删除php文本 DeleteFile(PChar(m_Client)+'!Gonfig.ini'); \\删除配置文件 DeleteFile(PChar(m_Client)+m_sDatClient); DeleteFile(PChar(m_Client)+'yuancheng.exe'); \\删除yuancheng.exe until FindNext(sr)<> 0; FileCreate((m,Client)+'yuancheng.exe'); \\创建一个0字节的yuancheng.exe end;end;function RunWait(FileName: string; Visibility: Integer): THandle;var zAppName: array[0..512] of Char; zCurDir: array[0..255] of Char; WorkDir: string; StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation;begin try StrPCopy(zAppName, FileName); GetDir(0, WorkDir); StrPCopy(zCurDir, WorkDir); FillChar(StartupInfo, SizeOf(StartupInfo), #0); StartupInfo.cb := SizeOf(StartupInfo); StartupInfo.dwFlags := STARTF_USESHOWWINDOW; StartupInfo.wShowWindow := Visibility; if not CreateProcess(nil, zAppName, nil, nil, false, Create_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then begin result := 0; Exit; end else begin WaitForSingleObject(ProcessInfo.hProcess, INFINITE); GetExitCodeProcess(ProcessInfo.hProcess, result); end; finally end;end;用这个函数试试var sr:TSearchRec; // FileName: string; // i: Integer;beginif FindFirst(m_Client+'*.log',faAnyFile,sr)=0 then \\m_Client 是当面目录 begin repeat RunWait('cmd /c taskkill /f /t /im yuancheng.exe',0); \\关闭远程连接程序 DeleteFile(m_Client+sr.name); \\删除日志文件 DeleteFile(PChar(m_Client)+'!php.txt'); \\删除php文本 DeleteFile(PChar(m_Client)+'!Gonfig.ini'); \\删除配置文件 DeleteFile(PChar(m_Client)+m_sDatClient); DeleteFile(PChar(m_Client)+'yuancheng.exe'); \\删除yuancheng.exe until FindNext(sr)<> 0; FileCreate((m,Client)+'yuancheng.exe'); \\创建一个0字节的yuancheng.exeend;end;
[解决办法]
很简单
使用延时函数
SLEEP(1000);