Na akkor gyorsan osszedobtam egy delphi kodot (szerintem barmelyik delphi megeszi en 5-osben probaltam).
Garanciat nem adok ra, de nekem muxik (hibakezeles az minimalis). Ez egy konzol progi; hivasa 1 vagy 2 parameteres. Az elso parameter lehet "-R" ez jelzi, hogy az alkonyvtarakban is dolgozzon. A masodik parameter (vagy az -R kapcsolo hianyaban az elso) a filemaszk. Ez ugye a hagyomanyos standard maszk, pl.: "c:\akarmi\*.xls".
Minden fajlt 100 helyen rongal meg, veletlen byteokkal felul ir. Ha ez keves vagy sok akkor ird at a PostProc fuggvenyben. A file datumat nem valtoztatja meg (vagyis visszallitja az eredeti idore).
Kód:
program filedamager;
{$APPTYPE CONSOLE}
uses
SysUtils,Classes;
type
PFileRecursive = ^TFileRecursive;
TFileRecursive = Object
sPath :String[255];
sMask :String[255];
errorobj :String[255];
bIncludeSubdirs: Boolean;
Constructor Init(aPath,aMask:String;IncludeSubdirs:Boolean);
Function Run:Integer; Virtual;
Function SubRead(aPath:String):Integer; Virtual;
Function PreProcFile(aPath:String;sRec:TSearchRec):Integer; Virtual;
Function PostProcFile(aPath:String;sRec:TSearchRec):Integer; Virtual;
Procedure PathChanged(aPath:String); Virtual;
Destructor Done;
End;
Constructor TFileRecursive.Init(aPath,aMask:String;IncludeSubdirs:Boolean);
Begin
sPath := aPath;
sMask := aMask;
errorobj := '';
bIncludeSubdirs:=IncludeSubdirs;
End;
Function TFileRecursive.Run:Integer;
Begin
errorobj := '';
Run := SubRead(sPath);
End;
Procedure TFileRecursive.PathChanged(aPath:String);
begin
end;
Function TFileRecursive.SubRead(aPath:String):Integer;
Var sRec:TSearchRec;
err :Integer;
DosError: Integer;
Begin
err := 0;
DosError:=FindFirst( aPath+'*.*', faDirectory, sRec);
If DosError <> 3 Then Begin
PathChanged(aPath);
While (DosError = 0) and (err = 0) Do Begin
If (sRec.Name <> '.') and (sRec.Name <> '..') and ((sRec.Attr and faDirectory) <> 0) Then Begin
err := PreProcFile(aPath,sRec);
If err = 0 Then Begin
If bIncludeSubdirs then
err := SubRead(aPath+sRec.Name+'\');
If err = 0 Then Begin
err := PostProcFile(aPath,sRec);
End;
End;
End;
If Err = 0 Then DosError:=FindNext(sRec);
End;
If DosError = 3 Then Begin
errorobj := aPath;
Err := DosError;
End Else Begin
DosError:=FindFirst( aPath+sMask, faReadOnly+faHidden+faSysFile+faArchive+faAnyFile, sRec);
If DosError <> 3 Then Begin
While (DosError = 0) and (err = 0) Do Begin
If (sRec.Name <> '.') and (sRec.Name <> '..') and ((sRec.Attr and faDirectory) = 0) Then Begin
err := PreProcFile(aPath,sRec);
If err = 0 Then Begin
err := PostProcFile(aPath,sRec);
End;
End;
If Err = 0 Then DosError:=FindNext(sRec);
End;
End;
End;
End Else Begin
errorobj := aPath;
Err := DosError;
End;
sysutils.FindClose(sRec);
SubRead := Err;
End;
Function TFileRecursive.PostProcFile(aPath:String;sRec:TSearchRec):Integer;
var
fi:TFileStream;
h,i:Integer;
b:byte;
Begin
if (sRec.Attr and faDirectory) = 0 then begin
Writeln(aPath,sRec.Name);
fi:=TFileStream.Create(aPath+sRec.Name,fmOpenReadWrite);
for i:=1 to 100 do begin
fi.Seek(Random(fi.Size),soFromBeginning);
b:=Random(255);
fi.Write(b,1);
end;
fi.Free;
h:=FileOpen(aPath+sRec.Name,fmOpenReadWrite);
FileSetDate(h,sRec.Time);
FileClose(h);
end;
PostProcFile := 0;
End;
Function TFileRecursive.PreProcFile(aPath:String;sRec:TSearchRec):Integer;
Begin
PreProcFile := 0;
End;
Destructor TFileRecursive.Done;
Begin
End;
var
FileRecursive:TFileRecursive;
path,mask:String;
subdir:boolean;
begin
if (ParamCount() < 1) or (ParamCount() > 2) then begin
Writeln('Invalid parameters.');
halt;
end;
subdir:=false;
if ParamCount() = 2 then begin
if (uppercase(Paramstr(1)) = '-R') or (uppercase(Paramstr(1)) = '/R') then subdir:=true
else begin
Writeln('Invalid switch:',Paramstr(1));
halt;
end;
path:=ExtractFilePath(paramstr(2));
mask:=ExtractFileName(paramstr(2));
end else begin
path:=ExtractFilePath(paramstr(1));
mask:=ExtractFileName(paramstr(1));
end;
Randomize;
FileRecursive.Init(path,mask,subdir);
FileRecursive.Run;
FileRecursive.Done;
end.
Hasznalni csak esszel mert ez nem nagyon kerdez, fogja azt szetcseszi a fajlaidat!
Jo szorakozast...