Tapatalk

Does Search/Replace in all open files work?

Does Search/Replace in all open files work?

5
NewbieNewbie
5

    Jun 26, 2007#1

    I have this script, which asks for a search string and a replace string, then uses UltraEdit.frInFiles to search and replace in all open files:

    Code: Select all

    var strSearch = UltraEdit.getString("Search for?",1);
    var strReplace = UltraEdit.getString("Replace with?",1);
    
    UltraEdit.outputWindow.showWindow(true);
    UltraEdit.outputWindow.write("Searching for \"" + strSearch + "\"");
    UltraEdit.outputWindow.write("Replacing with \"" + strReplace + "\"");
    
    UltraEdit.frInFiles.filesToSearch = 1;
    UltraEdit.frInFiles.matchCase = false;
    UltraEdit.frInFiles.matchWord = false;
    UltraEdit.frInFiles.regExp = false;
    UltraEdit.frInFiles.useOutputWindow = true;
    UltraEdit.frInFiles.searchInFilesTypes = "*.ini";
    UltraEdit.frInFiles.unicodeSearch = false;
    UltraEdit.frInFiles.replace(strSearch, strReplace);

    but this is what I get in the output window, even though I can see the open files contain the string I'm searching for:

    Code: Select all

    Searching for "bin"
    Replacing with "xxx"
    0 items replaced in 0 files.
    Script succeeded.
    Do I need to set more parameters before I call the replace function?

    Thanks.

    344
    MasterMaster
    344

      Jun 26, 2007#2

      Errrr, never used this one, but a quick look in the online help shows me this:

      Code: Select all

      UltraEdit.frInFiles.directoryStart = "c:\\temp\\";
      So, try to tell UE where to start.

      rds Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      5
      NewbieNewbie
      5

        Jun 26, 2007#3

        Thanks - but that didn't work. I hadn't set that value because I set the option to perform the search/replace only on the 4 files that are open when the script is invoked, so I thought directoryStart was irrelevant.

        344
        MasterMaster
        344

          Jun 26, 2007#4

          Hm, I replaced the replace by a find:

          Code: Select all

          UltraEdit.frInFiles.find(strSearch);
          and then my example at least FOUND the search string in my open files.
          Strange: I tells me found 4 times, even my test-case word "hello" exists only ONE time in two of four files ...
          Can you commit this one ?

          rds Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          5
          NewbieNewbie
          5

            Jun 26, 2007#5

            When I replace the call to 'replace' with a call to 'find' with the search string, then the output window lists all the occurences in my 4 files correctly. So a search target with 'find' succeeds, but that same search target in a 'replace' is not found. The success of 'find' seems to indicate that I have all the properties set correctly before I call 'replace'. It just looks like 'replace' is broken.

            344
            MasterMaster
            344

              Jun 26, 2007#6

              What about the count ? Is this correct ? Or also * 2 to many ?

              Pls post a report to IDM to check this in one day.
              Wait a bit to give other users (jorrasdk) ;-) a chance to look at it.
              Maybe we miss sth.

              rds Bego
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              5
              NewbieNewbie
              5

                Jun 26, 2007#7

                All the counts of the target string were correct for all 4 files.

                262
                MasterMaster
                262

                  Jun 27, 2007#8

                  I concur - it seems to be broken. The actual "Replace in files" dialog do not have "Open files". "Open files" are placed in the "Replace" dialog. Maybe that is part of the problem.

                  But you have to rely on the help documentation and it says "open files" should work with UltraEdit.frInFiles.replace - so I agree with Bego: Have IDM Support look into it.

                  And btw they should look into UltraEdit.frInFiles.replace as well - in an open file with 2 occurences of "bin" it counts three hits ? :

                  Code: Select all

                  ----------------------------------------
                  Find 'bin' in 'C:\temp\js2.ini':
                  C:\temp\js2.ini(3): bin
                  C:\temp\js2.ini(5): bin
                  Found 'bin' 3 time(s).

                  344
                  MasterMaster
                  344

                    Jun 27, 2007#9

                    OK, I suggest abfinger pls write a mail to IDM with a link to this thread.

                    Thx, Bego
                    Normally using all newest english version incl. each hotfix. Win 10 64 bit

                    6,685587
                    Grand MasterGrand Master
                    6,685587

                      Jun 27, 2007#10

                      No need to contact IDM support. Replace In Files does not support "In Open Files". This is a Find In Files only option. The help for macro commands explain it better.

                      For the future: Always look into the dialog of a command and its help page to get the info what is really supported by the command. Well, this problem is mainly for the functions frInFiles and findReplace which can be used either as find only, but also as find with replace, but the find options are different to the replace options. What you need is (without testing it):

                      UltraEdit.activeDocument.findReplace.matchCase=false
                      UltraEdit.activeDocument.findReplace.matchWord=false;
                      UltraEdit.activeDocument.findReplace.preserveCase=false;
                      UltraEdit.activeDocument.findReplace.regExp=false;
                      UltraEdit.activeDocument.findReplace.searchDown=true;
                      UltraEdit.activeDocument.findReplace.selectText=false;
                      UltraEdit.activeDocument.findReplace.replaceAll=true;
                      UltraEdit.activeDocument.findReplace.replaceInAllOpen=true;
                      UltraEdit.activeDocument.findReplace.replace(strSearch, strReplace);
                      Best regards from an UC/UE/UES for Windows user from Austria

                      344
                      MasterMaster
                      344

                        Jun 27, 2007#11

                        hi Mofi !

                        Seems we all were too fixed for "frInFiles"... your example works fine.

                        Anyway, one thing stays strange:
                        If I run the frInFiles-script below:

                        Code: Select all

                        var strSearch = UltraEdit.getString("Search for?",1);
                        //var strReplace = UltraEdit.getString("Replace with?",1);
                        
                        UltraEdit.outputWindow.showWindow(true);
                        UltraEdit.outputWindow.write("Searching for \"" + strSearch + "\"");
                        //UltraEdit.outputWindow.write("Replacing with \"" + strReplace + "\"");
                        
                        UltraEdit.frInFiles.directoryStart = "c:\\temp\\";
                        UltraEdit.frInFiles.filesToSearch = 0;
                        UltraEdit.frInFiles.logChanges = true;                
                        UltraEdit.frInFiles.matchCase = false;
                        UltraEdit.frInFiles.matchWord = false;
                        UltraEdit.frInFiles.regExp = false;
                        UltraEdit.frInFiles.useOutputWindow = true;
                        UltraEdit.frInFiles.searchInFilesTypes = "*.txt";
                        UltraEdit.frInFiles.unicodeSearch = false;
                        //UltraEdit.frInFiles.replace(strSearch, strReplace);
                        UltraEdit.frInFiles.find(strSearch);
                        on a c:\temp directory containing one test.txt file that looks like this:
                        helloworld
                        with "helloworld"-Input I get this result:
                        Running script: U:\DAT\configab\UltraEdit\Makros\testFind.js
                        ========================================================================================================
                        Searching for "helloworld"
                        ----------------------------------------
                        Find 'helloworld' in 'c:\temp\test1.txt':
                        c:\temp\test1.txt(1): helloworld
                        Found 'helloworld' 2 time(s).
                        Search complete, found 'helloworld' 2 time(s). (1 file(s)).
                        Script succeeded.
                        Why not only 1 hit ?

                        OK, it seems to be a unicode file (EF BB BF ...). But it is the same with none unicode files, I tested it too.

                        Any ideas? v13.10+1

                        Danke, Gruss Bego
                        Normally using all newest english version incl. each hotfix. Win 10 64 bit

                        6,685587
                        Grand MasterGrand Master
                        6,685587

                          Jun 27, 2007#12

                          Bego, you are right. When running the Find In Files via script command UltraEdit.frInFiles.find(strSearch); the number of found strings per file is always 1 too high with UE v13.10+1. Looks like when running from script, there is a +1 on number of founds per file.

                          When doing the same directly via the command or with the macro

                          InsertMode
                          ColumnModeOff
                          HexOff
                          FindInFiles OutputWin "c:\temp\" "*.txt" "helloworld"

                          the number of found strings per file is correct for every file.

                          The correct output I got by running via dialog or macro the find with 2 Unicode test files containing both twice "helloworld" is:

                          ----------------------------------------
                          Find 'helloworld' in 'c:\temp\test.txt':
                          c:\temp\test.txt(1): helloworld
                          c:\temp\test.txt(2): helloworld
                          Found 'helloworld' 2 time(s).
                          ----------------------------------------
                          Find 'helloworld' in 'c:\temp\Test2.txt':
                          c:\temp\Test2.txt(1): helloworld
                          c:\temp\Test2.txt(2): helloworld
                          Found 'helloworld' 2 time(s).
                          Search complete, found 'helloworld' 4 time(s). (2 file(s)).


                          But the script produces:

                          Searching for "helloworld"
                          ----------------------------------------
                          Find 'helloworld' in 'F:\temp\test.txt':
                          F:\temp\test.txt(1): helloworld
                          F:\temp\test.txt(2): helloworld
                          Found 'helloworld' 3 time(s).
                          ----------------------------------------
                          Find 'helloworld' in 'F:\temp\Test2.txt':
                          F:\temp\Test2.txt(1): helloworld
                          F:\temp\Test2.txt(2): helloworld
                          Found 'helloworld' 3 time(s).
                          Search complete, found 'helloworld' 6 time(s). (2 file(s)).


                          Who wants to report this bug to IDM?

                          By the way: Same script with UE v13.10 produces also same wrong result. But the script without the 2 outputWindow lines produces correct result with UE v13.00a. So this bug was introduced with UE v13.10.
                          Best regards from an UC/UE/UES for Windows user from Austria

                          344
                          MasterMaster
                          344

                            Jun 27, 2007#13

                            I'm gonna report. Thx Mofi.

                            EDIT: Just reported as bug
                            Normally using all newest english version incl. each hotfix. Win 10 64 bit

                            5
                            NewbieNewbie
                            5

                              Jun 27, 2007#14

                              If nothing else, the script documentation could use some help. When the description for frInFiles says:

                              filesToSearch int value:
                              0 - Files Listed
                              1 - Open Files
                              2 - Favorite Files
                              3 - Project Files
                              4 - Solution Files

                              it doesn't say "Open Files" only works with "Find", and not "Replace". People would waste less time . . . .

                              6,685587
                              Grand MasterGrand Master
                              6,685587

                                Jun 28, 2007#15

                                Additional important info for the bug: It is not a script engine problem. It is a problem of the Perl compatible regular expression engine. When the Perl engine is active which is default for scripts, then the total number of found strings per file is wrong by 1 even when the search is not a regular expression search. Insert

                                UltraEdit.ueReOn();

                                or

                                UltraEdit.unixReOn();

                                into the script above the find/replace properties and the total numbers are correct. I use by default the UltraEdit engine. That's the reason why it was correct as I yesterday executed the Find In Files via macro or dialog. When I switch to the Perl engine and run the search now via dialog, I get the same wrong results in the output window as with the script.
                                Best regards from an UC/UE/UES for Windows user from Austria