最简单地锁定文件夹!!!

本文章来自http://blog.csdn.net/hellogv/


/以下是锁定文件夹的方法 procedure TSysClass.QuickLock(DirList:TStrings); //DirList是保存文件夹的列表 var UnLockDIRList:TStrings; i:integer; IsLock:boolean; begin UnLockDIRList:=TStringList.Create; UnLockDIRList.Add('以下目录锁定失败,请检查有文件是否正被使用或者是空文件夹:'); for i:=0 to DIRList.Count -1 do begin IsLock:=false;//本来就是锁定失败 if GetDirSize(DirList.Strings[i],true)>0 then //如果文件夹不为空 ,则执行下面语句,如果为空则ISLock=false IsLock:=RenameFile(DIRList.Strings[i],DIRList.Strings[i]+'../'); //通过修改文件夹名称来检测文件夹是否可以锁定 if IsLock= false then begin //如果锁定失败,则记录目录夹名称 UnLockDIRList.Add(DIRList.Strings[i]); end; end; if UnLockDIRList.Count = 1 then begin //全文件夹成功被锁定 ShowMessage('文件夹锁定成功!'); exit; end; if UnLockDIRList.Count > 1 then //部分文件夹没有被锁定 ShowMessage(UnLockDIRList.Text); UnLockDIRList.Free; end; /以下是解锁文件夹的方法 procedure TSysClass.UnLock(DIRList:TStrings); var i,ii:integer; FileList:TStrings; label loop; begin FileList:=TStringList.Create; for i:=0 to DirList.Count -1 do begin //-----------------------------先创建锁定文件夹的入口 FileList.Clear; CreateDir(DirList.Strings[i]+'./') ;//创建锁定文件夹的入口 FindAll(DirList.Strings[i]+'./',FileList); SysFunctions.FileMove(DirList.Strings[i]);//文件解密成功或不用解密直接解锁文件夹 loop: end; ShowMessage('成功解锁文件夹!'+#10+'如果被锁定的文件夹还没有被删除'+#10+'请不要手动删除'+#10+'本程序关闭时会自动删除!'); end; procedure TSysClass.FindAll(path: String; var fileresult: TStrings);//查找文件 ,path不带'/' var fpath,s: String; fs: TsearchRec; i:integer; begin fpath:=path+'/*.*'; if FindFirst(fpath,faAnyFile,fs)=0 then begin if (fs.Name<>'.')and(fs.Name<>'..') then if (fs.Attr and faDirectory)=faDirectory then findall(path+'/'+fs.Name,fileresult) else fileresult.add(path+'/'+fs.Name); while findnext(fs)=0 do begin if (fs.Name<>'.')and(fs.Name<>'..') then if (fs.Attr and faDirectory)=faDirectory then Findall(path+'/'+fs.Name,fileresult) else begin fileresult.add(path+'/'+fs.Name); end; end; end; Findclose(fs); end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值