网上有相关的在win2000下实现对文件的监控,但是在win98下面都调试不成功,所以哪位朋友有相关代码的话,本人万分感激,我要实现的是这样一个功能: 监视系统的某个目录及子目录,如果出现某一类型的文件,就将其他扩展名改为.3bb,主要是为了实现备份功能,但对相关对目录进行监控的代码找了几个对win98下的都没办法,所以在这里求救... 我要监视的是类似DOS的EDIT程序的保存动作,因为我用到的这个程序只能在98下运行,所以....问题解决300分相送,绝不食言.... (解决后再开两贴给分)
在 Sample 面板下
procedure FindFile(Path: String; Ext1,Ext2: string);
var
hData: TWin32FindData;
hFile: THandle;
FileType: String;
begin
hFile := FindFirstFile(PAnsiChar(Path + '\*.*'), hData);
if hFile <> INVALID_HANDLE_VALUE then
repeat
begin
{--- 屏蔽掉'.'和'..'目录 ---}
if (hData.cFileName[0] = '.') then
Continue;
{--- 若找到的是二级文件目录则在此目录下递归查找 ---}
if hData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
FindFile(Path + '\' + hData.cFileName, Ext1, Ext2)
else
{--- 若找到的是Ext1的文件则改扩展名为Ext2 ---}
begin
FileType := Copy(hData.cFileName, Pos('.', hData.cFileName), 4);
if FileType = Ext1 then
ReNameFile(Path + '\' + hData.cFileName, ChangeFileExt(Path + '\' + hData.cFileName,Ext2));
end;
end;
until not FindNextFile(hFile, hData)
else
begin
ShowMessage(Path + ' is not exist');
Exit;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
FindFile('C:\temp', '.txt', '.3bb');
end;
如果你是要實現這個, 是可以的
http://community.csdn.net/Expert/topic/2767/2767861.xml?temp=.669552
只是在DOTNET中有这么一个类FileSystemWatcher
可以知道对文件的改名.删除等操作