Results 1 to 9 of 9

Thread: Simba file checker

  1. #1
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default Simba file checker

    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.

    Simba Code:
    (*******************************************************************************

                        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(path), 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}
    Last edited by Zyt3x; 04-30-2015 at 04:56 PM. Reason: Fixed

  2. #2
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    I'm gonna test this ASAP. Nice work, Zyt3x.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  3. #3
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    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 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!
    Last edited by Zyt3x; 12-04-2011 at 04:34 AM.

  4. #4
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    It might be a good idea to use try/except cases for if you get permission denied etc it won't stop the script.


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  5. #5
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by Harry View Post
    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

  6. #6
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Updated original post and script.

  7. #7
    Join Date
    Jan 2015
    Posts
    16
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    sorry someone have a specific guide to use simba? cause i tried from the website but i dont understand it very well

  8. #8
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by heroludor View Post
    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
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  9. #9
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    I wrote something similar to this last year, i didn't bother to encapsulate the code into separate functions though
    Simba Code:
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •