文件切割子程序

//分解文件夹 SDir:源目录名 DDir:目的目录名 SQZ:生成的子目录(前)后缀名

//SExt:文件类型 MNum:每个文件夹的文件数目 B:SQZ为前缀还是后缀名

procedure CutDir(SDir,DDir,SQZ,SExt:string;MNum:integer;B:Boolean;handle:THandle);

var

i,iFileCount,iFileNum,iDirCount,iDirNum:integer;

tsr:TStringList;

DFileName,SFileName:string;

bSearch:Boolean;

begin

bSearch:=False;

tsr:=TStringList.Create;

tsr:=FkFileListGet(SExt,SDir,False);

if SDir[Length(SDir)]<>'/' then

SDir :=SDir+'/';

if DDir[Length(DDir)]<>'/' then

DDir :=DDir+'/';

for i:=0 to tsr.count-1 do

begin

SFileName:=tsr[i];

if not bSearch then

begin

iDirCount :=GetDirCount(SDir+'*.*');

iDirNum :=iDirCount;

end;

if iDirNum=0 then

begin

if B then

begin

MkDir(DDir+SQZ+'1');

DFileName:=DDir+SQZ+'1/'+ExtractFileName(SFileName);

end

else

begin

MkDir(DDir+'1'+SQZ);

DFileName:=DDir+'1'+SQZ+'/'+ExtractFileName(SFileName);

end;

iFileNum :=1;

end

else

begin

if not bSearch then

begin

if B then

iFileCount:=GetFileCount(DDir+SQZ+IntToStr(iDirCount) ,SExt)

else

iFileCount:=GetFileCount(DDir+SQZ+IntToStr(iDirCount) +SQZ,SExt)

iFileName :=iFileCount;

bSearch :=True;

end;

if iFileNum>=MNum then

begin

if B then

begin

MKDir(DDir+SQZ+IntToStr(iDirNum+1));

DFileName :=DDir+SQZ+IntToStr(iDirNum+1)+'/'+ExtractFileName(SFileName);

end

else

begin

MKDir(DDir+SQZ+IntToStr(iDirNum+1)+SQZ);

DFileName :=DDir+IntToStr(iDirNum+1)+SQZ+'/'+ExtractFileName(SFileName);

end;

iDirNum :=iDirNum+1;

iFileNum :=1;

end

else

begin

if B then

DFileName:=DDir+SQZ+IntToStr(iDirNum)+'/'+ExtractFileName(SFileName);

else

DFileName:=DDir+IntToStr(iDirNum)++SQZ+'/'+ExtractFileName(SFileName);

iFileNum:=iFileNum+1;

end;

end;

MoveFile(Handle,SFileName,DFileName);

end;

end;

//调用实例,将F:/djcproj/技术文章内的所有txt文件以每20个作为一个文件夹的形式,切割到各子目录中,且子目录形//式为S1,S2.....

CutDir('F:/djcproj/技术文章','F:/djcproc/技术文章','S','*.txt',20,True,Handle);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值