PDA

View Full Version : Simba file checker



Zyt3x
12-04-2011, 04:16 AM
This script snippet will search all files with the extension EXT in all folders and sub-folders starting from folder DIR for the search string STRING or regex using REGEX, with an added option of case sensitivity using CASESENS.

For when you're looking for a specific procedure/function/type record/whatever and can't find it yourself.

Remember to use the lape interpreter when you run this script. Alternatively you can use the older Pascal Script version here (http://paste.villavu.com/show/5805/).

(************************************************* ******************************

SIMBA FILE CHECKER v3
- BY ZYT3X
03 Jan 2013

************************************************** *****************************)
{$DEFINE ssTest}

{$IFDEF ssTest}
const
DEFAULTDIR = 'C:\SkyDrive\Private\Programming\Scripting\';
{$ENDIF}

{$IFDEF LAPE}

{$IFNDEF SRL}
// From SRL-6
procedure TStringArray.append(const str : String; const index : Integer);
var
I : Integer;
begin
setLength(self, length(self)+1);
for I := high(self)-1 downto index do
self[I+1] := self[I];
self[index] := str;
end;

// From SRL-6
procedure TStringArray.append(const str : String); overload;
begin
self.append(str, length(self));
end;

// From SRL-6
function TStringArray.returnInArray(const str : String) : Integer;
var
I : Integer;
begin
result := -1;
for I := 0 to high(self) do
if self[I] = str then
begin
result := I;
exit;
end;
end;

// From SRL-6
function TStringArray.isInArray(const str : String) : Boolean;
begin
result := returnInArray(str) > -1;
end;

// From SRL-6
procedure TStringArray.clearSame();
var
I : Integer;
arr : TStringArray;
begin
for I := 0 to high(self) do
if not arr.isInArray(self[I]) then
arr.append(self[I]);
self := arr;
end;
{$ENDIF}

function getAllDirectoriesFromPath(const path : String) : TStringArray;
var
I, J, H : Integer;
dirs : TStringArray;
begin
result := getDirectories(path);
for I := 0 to high(result) do
result[I] := path + result[I] + '\';

while (high(result) <> H) do
begin
H := high(result);
for J := 0 to H do
begin
dirs := getDirectories(result[J]);
for I := 0 to high(dirs) do
result.append(result[J] + dirs[I] + '\');
end;
result.clearSame();
end;
result.append(path);
end;

function getAllFilesFromPaths(const paths : TStringArray;
const extType : String) : TStringArray;
var
I, J : Integer;
files : TStringArray;
begin
for J := 0 to high(paths) do
begin
files := getFiles(paths[J], extType);
for I := 0 to high(files) do
result.append(paths[J] + files[I]);
end;
result.clearSame();
end;

function getAllFilesFromPath(const path, extType : String) : TStringArray;
begin
result := getAllFilesFromPaths(getAllDirectoriesFromPath(pat h), extType);
end;

function searchAllFilesFromPaths(const searchString : String;
const paths : TStringArray; const extension : String;
const regexSearch, caseSensitive : Boolean = False): TStringArray;
var
allFiles := getAllFilesFromPaths(paths, extension);
F, I : Integer;
S, searchStr : String;
found : Boolean;
begin
searchStr := searchString;
if not caseSensitive then
searchStr := lowerCase(searchString);

for I := 0 to high(allFiles) do
begin
if not fileExists(allFiles[I]) then continue;
try
F := openFile(allFiles[I], False);
readFileString(F, S, fileSize(F));
closeFile(F);
except
continue;
end;

if not caseSensitive then
S := lowerCase(S);

case regexSearch of
True: found := execRegExpr(searchStr, S);
False: found := pos(searchStr, S) <> 0;
end;

if found then
result.append(allFiles[I]);
end;
end;

function searchAllFilesFromPath(const searchString, path, extension : String;
const regexSearch, caseSensitivity : Boolean = False): TStringArray;
begin
result := searchAllFilesFromPaths(searchString,
getAllDirectoriesFromPath(path), extension, regexSearch, caseSensitivity);
end;

{$IFDEF ssTest}
var
found : TStringArray;
I : Integer;
SEARCH, DIR, RES : String;
REGEX, CASESENS : Boolean;
begin
if not inputQuery('Script Searcher', 'Input search string:', SEARCH) then exit();
if SEARCH = '' then exit();
inputQuery('Script Searcher', 'Input search path start: (has to end with a \)', DIR);
if DIR = '' then DIR := DEFAULTDIR;
REGEX := messageDlg('Script Searcher', 'Use Regex search?', mtConfirmation, [mbYes, mbNo]) = 1;
CASESENS := messageDlg('Script Searcher', 'Use Case sensitivity?', mtConfirmation, [mbYes, mbNo]) = 1;
found := searchAllFilesFromPath(SEARCH, DIR, 'simba', REGEX, CASESENS);
if length(found) > 0 then
begin
messageBox(toStr(length(found)) + ' scripts found containing ' + SEARCH, 'Script Searcher', 0);
writeLn('Scripts containing '#39 + SEARCH + #39':');
end else
messageBox('No scripts found.', 'Script Searcher', 0);
for I := 0 to high(found) do
writeLn(' (' + toStr(I+1) + '): ' + between(DIR, #13, found[I]+#13));
end.
{$ENDIF}

{$ELSE}
begin
messageDlg('Script Searcher', 'Cannot run the Script Searcher when the interpeter is set to Pascal Script, to fix this go-to: (Script > Interepeter > Select Lape)', mtError, [mbOk]);
end;
{$ENDIF}

Flight
12-04-2011, 04:19 AM
I'm gonna test this ASAP. Nice work, Zyt3x.

Zyt3x
12-04-2011, 04:23 AM
I'm gonna test this ASAP. Nice work, Zyt3x.Thanks :)
Random Fact: Note that this is version 2; it's a revamped version of an old file checker that I made :p You'll find the old version if you lurk around a lot (Coh3n posted it), heh..

E: I should make it possible to search with regex too, probably... That would be *really* neat...Done!

Harry
12-04-2011, 04:40 AM
It might be a good idea to use try/except cases for if you get permission denied etc it won't stop the script.

Zyt3x
12-04-2011, 04:43 AM
It might be a good idea to use try/except cases for if you get permission denied etc it won't stop the script.Well, if one gets permission denied I'd guess it wouldn't find *anything* at all...
I added it nevertheless

Zyt3x
02-26-2014, 07:19 AM
Updated original post and script.

heroludor
01-10-2015, 05:33 PM
sorry someone have a specific guide to use simba? cause i tried from the website but i dont understand it very well

KeepBotting
01-10-2015, 06:09 PM
sorry someone have a specific guide to use simba? cause i tried from the website but i dont understand it very well

https://villavu.com/forum/showthread.php?t=47714

riwu
01-11-2015, 12:11 AM
I wrote something similar to this last year, i didn't bother to encapsulate the code into separate functions though :D

dir:= ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

if not IsStrInArr(AppPath[1], false, dir) then
begin
SetLength(dir, Length(dir) + 1);
dir[High(dir)] := AppPath[1];
end;

for i:= 0 to high(dir) do
dir[i] := dir[i] + AppPath[2] + AppPath[3];

len:= High(dir);
for i:=0 to len do
begin
for i3:=0 to High(ext) do
begin
files:= GetFiles(dir[i], ext[i3]);
for i2:=0 to High(files) do
begin
//
end;
end;

path:= GetDirectories(dir[i]);
for i2:=0 to High(path) do
begin
SetLength(dir, Length(dir) + 1);
dir[High(dir)]:= dir[i] + path[i2] + AppPath[3];
end;

len:= High(dir);
end;

writeln(dir); //generates all folders/subfolders on PC