Page 1 of 2

request:find strings that are not in files of tab

Posted: 23 Dec 2013 11:14
by DmFedorov
script to search for text strings that are not in the content of files in the current tab.
For example I have a list of strings, and it is placed in a text file or in clipboard.
I need to find a list of those strings that are not in the content of files in the current tab.
As a result, it is necessary to bring these list into the box for viewing and copying.

I need such script to know that the translation strings contained in the files of folder were not deleted or changed in these files.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 11:45
by 40k
Let me try something.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 11:55
by DmFedorov
You can open any folder. Find in files of this folder 3 or 4 strings in their content, and create any strings that do not appear in the files. Then you can try.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 12:06
by 40k
DmFedorov wrote:You can open any folder. Find in files of this folder 3 or 4 strings in their content, and create any strings that do not appear in the files. Then you can try.
I have an idea. Give me some time.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 12:19
by 40k

Code: Select all

"Findstrings"
 {
 $in = readfile('c:\in.txt', 't', , , );
 $out = writefile('c:\out.txt', '', 'o', 't');
 
 $files = get('selecteditemspathnames', '|', 'a');
 $hashes = regexmatches($in, '[^\n]+', '|', '0');
 
 foreach($file, $files, '|'){
	$content = readfile($file, 't', , , );
	writefile('c:\out.txt', "$file<crlf>", 'a', 't');
	
	foreach($hash, $hashes, '|'){
		if (regexmatches($content, $hash, '|', '0')){
			// string was found. no action required
			}
		else {
			// string was not found. adding hash to list of items
			writefile('c:\out.txt', "$hash<crlf>", 'a', 't');	
			}	
		}
	writefile('c:\out.txt', "----------------<crlf>", 'a', 't')	
	}
 text readfile('c:\out.txt', 't', , , );
 }
How it works:
1. Enter all your text strings in the text file in.txt and place it in c:\ (or update the script to the correct location with variable $in)
ONLY ONE STRING PER LINE. PUSH ENTER AFTER EVERY STRING!
2. select all the files that you want to search through in your window. you MUST select the files.
3. Script will show a text dialogue with the name of each file and the strings from in.txt that were NOT found inside your file

disclaimer: sloppy code, I haven't had my coffee yet.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 12:35
by DmFedorov
Thank you very match. I'll try this script in an hour.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 12:57
by highend
- Let's you enter the strings that should not be present into a dialog box (must be separated by |)
- If you don't enter anything it'll ask for a filename which contains these strings
- Pops up a text box with all files with their missing strings
- Goes through all files in the current directory, no manual selection first (skips binary files)

Code: Select all

    $searchStrings = input("Enter the search terms...", "Terms MUST be separated by |", , "s", "empty", 600, 200);
    if ($searchStrings == "") {
        $searchStringsFile = inputfile("<curpath>", , "You did not enter any search terms, please select the file that contains them...<crlf>Terms MUST be separated by |");
        $searchStrings = readfile($searchStringsFile);
    }

    $allFiles = listfolder(, "*", 1, "|");

    $fileWithMissingString = "";
    foreach($file, $allFiles, "|") {
        if (filetype($file) != "Binary") {
            $markFile = "";
            $notFoundStrings = "";
            $fileContent = readfile($file);

            foreach($string, $searchStrings, "|") {
                if (strpos($fileContent, $string) == -1) {
                    $notFoundStrings = $notFoundStrings . $string . "|";
                    $markFile = 1;
                }
            }

            if (substr($notFoundStrings, -1) == "|") {
                $notFoundStrings = regexreplace($notFoundStrings, "\|$", "");
            }
            if ($markFile) {
                $fileWithMissingString = $fileWithMissingString . $file . " - " . $notFoundStrings . "<crlf>";
            }
        }
    }
    text $fileWithMissingString;

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 13:11
by 40k
highend wrote: - Goes through all files in the current directory, no manual selection first (skips binary files)
Probably will need to exclude anything that isn't ASCII or UTF-8 encoded. However I think it's safe to assume OP will just group the files he needs beforehand so that kind of error handling isn't vital. Nice touch though.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 13:49
by highend
However I think it's safe to assume OP will just group the files he needs beforehand
That's what I did :biggrin:

Small change (to not cancel the whole script if you press cancel on the first inputbox):

Code: Select all

    $searchStrings = input("Enter the search terms...", "Terms MUST be separated by |", , "s", "none", 600, 200);
    if ($searchStrings == "" || $searchStrings == "none") {

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 13:50
by DmFedorov
I need to find a list of those strings that are not in the content of files in the current tab.
-------------------------
highend and 40k
If I have for example 4 files and 3 strings:

F:\_New\inspector.js
F:\_New\NetworkPanel.js
F:\_New\ProfilesPanel.js
F:\_New\ResourcesPanel.js

You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
where third string "Save entry as HAR" is missing in files, I have in box:

F:\_New\inspector.js - Save entry as HAR
F:\_New\NetworkPanel.js - You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
F:\_New\ProfilesPanel.js - You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
F:\_New\ResourcesPanel.js - You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
-----------------------
but I must have in this case only this:

Save entry as HAR

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 13:56
by 40k
DmFedorov wrote:I need to find a list of those strings that are not in the content of files in the current tab.
-------------------------
highend and 40k
If I have for example 4 files and 3 strings:

F:\_New\inspector.js
F:\_New\NetworkPanel.js
F:\_New\ProfilesPanel.js
F:\_New\ResourcesPanel.js

You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
where third string "Save entry as HAR" is missing in files, I have in box:

F:\_New\inspector.js - Save entry as HAR
F:\_New\NetworkPanel.js - You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
F:\_New\ProfilesPanel.js - You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
F:\_New\ResourcesPanel.js - You need to install a Chrome extension|Remove all DOM breakpoints|Save entry as HAR
-----------------------
but I must have in this case only this:

Save entry as HAR
That's highend's script. Can you post what is the output of mine?

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 13:57
by highend
where third string "Save entry as HAR" is missing in files
You mean: It's only missing in the file "inspector.js"...
but I must have in this case only this:

Save entry as HAR
You've said that you want the file together with the missing strings, so the output should still be:
D:\Temp\test\inspector.js - Save entry as HAR

And that's exactly what I get when I use my script on your 4 files...

Attached a small animation as a proof...

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 14:08
by 40k
What program do you use make a gif like that highend? Looks really nice.

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 14:13
by DmFedorov
40k
With your script I receive

F:\_New\inspector.js
You need to install a Chrome extension
Remove all DOM breakpoints
Save entry as HAR
----------------
F:\_New\NetworkPanel.js
You need to install a Chrome extension
Remove all DOM breakpoints
Save entry as HAR
----------------
F:\_New\ProfilesPanel.js
You need to install a Chrome extension
Remove all DOM breakpoints
Save entry as HAR
----------------
F:\_New\ResourcesPanel.js
You need to install a Chrome extension
Remove all DOM breakpoints
Save entry as HAR
----------------

Re: request:find strings that are not in files of tab

Posted: 23 Dec 2013 14:14
by highend
40k wrote:What program do you use make a gif like that highend? Looks really nice.
It's made by GifCam (http://blog.bahraniapps.com/?page_id=21)

Resized it to 800 x 600... Looks awful... I'll remove it after the OP next answer anyway...