Find files that don't contain
-
Hi Guys.
What expression would I need to find all files in a folder that don’t contain say
Add-Content -path *.cfg -Value ‘input_overlay_enable = “true”’
I have about 1000 files and I know some of them won’t have that line present. I just don’t know which ones.
Thanks in advance.
-
Your question is kind of similar to this old one: https://community.notepad-plus-plus.org/topic/16141/find-content-in-files-and-rename-delete-files-not-containing-content
As well as this one: https://community.notepad-plus-plus.org/topic/14870/regex-find-all-files-that-do-not-contain-some-words
-
However, if it is too much reading for you–I just read it, there’s A LOT there–then this might work for your situation:
Find what box:
(?s)\A(?:(?!\QAdd-Content -path *.cfg -Value 'input_overlay_enable = "true"'\E).)+\z -
Thanks mate. No its not to much reading at all. Simply pointing me in the right direction would have been a sufficient answer.
Thank you for the time it took you.
-
Hello, @craig-mcfarlane, @alan-kilborn and All,
Certainly, the regex, below, does work properly in the majority of cases :
SEARCH
(?s-i)\A(?:(?!\QYour Expression\E).)+\zHowever, when files scanned have a size greater than
8 Mb, about, this regex may fail and wrongly matches a file which does contain your specific expression ! I did some tests with such a file, containing the stringYour expressiononce only !
If so, here is a quicker and safer regex which is able to handle huge files. I personally tested a file of
56 Mband2,000,000lines, without any trouble ! This file contained only a single line with the stringYour expression;-))SEARCH
(?s-i)\A(?!.*\QYour Expression\E).+=> You’ll get your expected list of files which do not contain the string
Your expression, with this exact case ;-))Best Regards,
guy038
P.S. :
In order to get the list of the files, with their full path, displayed in the
Find resultpanel, pasted into a new tab, follow these steps :-
Right-click on any zone of the
Find resultpanel -
Select the
Select alloption -
Hit the
Ctrl + Cshortcut ( do not use theCopyoption ! ) -
Hit the
Ctrl + Nshortcut to open a new N++ tab -
Hit the
Ctrl + Vshortcut to paste the results, into this new tab -
Finally, perform the following regex S/R, below :
-
SEARCH
^(?!\x20\x20).*\R|\Q (1 hit)\E$ -
REPLACE
Leave EMPTY
-
-
-
Thank you so much for a helpful and constructive reply. I am learning and this really helped a lot. Thanks for a clear explanation.
-
A Alan Kilborn referenced this topic on
-
Here’s a real feature request for making “Find files that don’t contain” a part of standard Notepad++: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/15680