Jump to content

Find in File


llewxam
 Share

Recommended Posts

This app has been designed to help search for text within files, and has the following features:

  • The phrase searched for can be case sensitive or not
  • The file search can be recursive through subdirectories or not
  • File masks for included or excluded file types are available

I posted this in another thread as it was when I last worked on it last June, and got a very helpful tip from Melba23 regarding how to make .docx and .xlsx files searchable (though I did it in a very different way :) ).  I now also use UEZ's File to Base64 String Code Generator to bundle the 7-Zip dll and exe in to the script for use on the new Office files, so the script is rather large.  The other major change from the earlier version I posted is that if the file being searched is over 32MB then the file is searched in chunks to avoid the horrible memory allocation errors I got during testing when _WinAPI_ReadFile tried reading a 3GB video file in one piece.   ;)

If there are any file types that need special attention to open properly or other feature requests please let me know.

Ian

Updated code 3/9/15, previous version downloaded 89 times

Updated code 3/11/15, bug fix and added topmost option

Find In File.7z

Edited by llewxam

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

Very Nice Man !!

Just what I was looking for to search for context sensitive references in a css file.

One question - Whats the percent reading in the bottom right corner for? it doesn't seem to jive with anything else that is going on...

Feature Request - "Open with" context menu or be able to drag and drop the file out on to another program icon to open with scite or editor etc.  o:)

Other than that.... :thumbsup:

cya,

Bill

Link to comment
Share on other sites

Seems to working properly!

It would be cool to open the file also with double click.

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Double-click to open can do. Context menu to open with might be easier said than done since not all editors etc have a standard syntax but drag should be doable, I think. I have done drag in, never drag out, but I like the idea so I'll play with that.

The percent at the lower right is percent complete scanning tbe current file. I know it is likely to almost always say 100% because most of us keep documents in one place and media files elsewhere. But during my testing I had some xlsx and other files on my desktop, and I had a folder on the desktop containing some huge video files. WinAPI_FileRead tried opening them in one big chunk, leading to a memory allocation error and a crash. That is why I set a maximum buffer size of 32MB and if the file is larger then it reads it in 32MB chunks, and that is why the percent in the lower-right is there - so it doesn't look like the app is frozen on a huge file read. On the next update I will have that be blank unless there is something other than 100% to show, because I agree that it looks pointless when just scanning document files and it always says 100%. I guess I forgot to fix that before posting.....

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

llewxam,

i tested your code with 5 file types: pdf, doc, xls, ppt, msg (attached).

all files contain only this text: Text in English

search phrase: English (not case sensitive)

the search phrase was found only in the doc, xls & ppt files - not in the pdf or msg

perhaps this test will aid you in improving your program - or perhaps i was doing something wrong?

other comments:

- why not use FileInstall for the 7z files?

- enable drop into the search location InputBox.

- when analyzing XML files you should strip tags (probably a simple RegExpReplace)

English.zip

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Thanks for posting your sample files, though I am not on the computer yet so haven't downloaded them for testing. I was finding phrases in PDF files but again, thanks for posting the files you used! BTW, I did not test on msg and am glad you did, will be valuable to add that.

I chose going with the 7-Zip files inline instead of FileInstall just because that now feels clunky to me - I would have to include them in an archive in the post here anyway, the executable would be about the same size, and that would be yet another folder with 2 7-Zip files in it! :P Going inline seems much better to me, but by all means change it on your end if you wish.

Drag/drop to input is already there with last nights changes, few more things before I post it.

As for your XML request, I have always loathed XML so don't understand why tags would need to go - why would the phrase you are searching for not be within one tag? If I just don't understand then please help me to, I'll definately help support XML by removing tags if the need is legit but every special case added will cause a small slowdown.

Thanks

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

llewxam,
A really good work

it possible to even add
the opportunity to see the string or line where it was found the "phrase"?
Maybe with a button that opens an array in columns?

thanks

Link to comment
Share on other sites

hmmmmmm, something like that could be arranged, a little preview. I dig it.

Thanks

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

I think it is important even read the "phrase" or "word" in that line or string exists,

for every line that exists in a file

For those who have many files

it is important to read the "thought" where is located the "phrase" to search.

But it's my idea...

Thanks

Link to comment
Share on other sites

Got some updates worked in:

  • Drag path in to "Location to search in" input box, if a file is specified then the file name is removed so the whole folder is searched
  • Open With button added
  • Percent scanning each file no longer shows unless the file is over 32MB

 

Still to do:

  • Double click to open
  • Look in to certain PDF file failures (thanks orbs for posting the sample files, issue confirmed)
  • Look in to opening MSG files
  • Preview function

 

Not gonna happen:

  • Drag file out of results ListView to open with app of choice, I could not find a way to do that

 

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

A topmost style would be cool to drag and drop from a full screen browser to the GUI without reducing the windows size of the browser first.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Agreed, I usually just take Explorer out of full screen to drag but I hear ya. Consider it added to the to-do list.

Thanks

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

FYI,

this function works for msg files (although not for pdf) - tested on the uploaded samples at post #5:

Func FileHasText($sFile, $sPhrase)
    ; init
    Local $hFile, $sFileContents
    ; True if no text specified
    If $sPhrase = '' Then Return True
    ; search ANSI
    $hFile = FileOpen($sFile)
    $sFileContents = FileRead($hFile)
    FileClose($hFile)
    If StringInStr($sFileContents, $sPhrase) Then Return True
    ; search UTF16 Little Endian
    $hFile = FileOpen($sFile, 32)
    $sFileContents = FileRead($hFile)
    FileClose($hFile)
    If StringInStr($sFileContents, $sPhrase) Then Return True
    ; text not found
    Return False
EndFunc

except from the buffering, i'm not sure exactly how it differs from the OP function that uses _WinAPI_ReadFile (which has no encoding specification, as far as i can see).

this function reads the file in two encoding types - ANSI and UTF16 Little Endian. i tried the other encoding types available, none produced any better result.

tested on English text only. i'm now checking and adjusting for other languages.

if anyone can shed some light on how encoding is (or is not) relevant here, please do.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Updated code to include a topmost button for when you do or do not want this to be on top of all other windows.  Mainly updated though due to a silly bug I realized out of nowhere - the way I was checking to see if a file or a folder was dragged in to the "Location to search in" box was preventing typing the location in, it would immediately get wiped out.  Ooooops........

As for adding Enter as a hotkey, I did that in an earlier test version but had to remove it because I am a keyboard shortcut nut and use Enter when selecting the folder I want to search in, which was prematurely running the search before I could enter file masks.

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

FYI,

this function works for msg files (although not for pdf) - tested on the uploaded samples at post #5:

Func FileHasText($sFile, $sPhrase)
    ; init
    Local $hFile, $sFileContents
    ; True if no text specified
    If $sPhrase = '' Then Return True
    ; search ANSI
    $hFile = FileOpen($sFile)
    $sFileContents = FileRead($hFile)
    FileClose($hFile)
    If StringInStr($sFileContents, $sPhrase) Then Return True
    ; search UTF16 Little Endian
    $hFile = FileOpen($sFile, 32)
    $sFileContents = FileRead($hFile)
    FileClose($hFile)
    If StringInStr($sFileContents, $sPhrase) Then Return True
    ; text not found
    Return False
EndFunc

except from the buffering, i'm not sure exactly how it differs from the OP function that uses _WinAPI_ReadFile (which has no encoding specification, as far as i can see).

this function reads the file in two encoding types - ANSI and UTF16 Little Endian. i tried the other encoding types available, none produced any better result.

tested on English text only. i'm now checking and adjusting for other languages.

if anyone can shed some light on how encoding is (or is not) relevant here, please do.

huh, that is highly strange.  I'll poke around at that but don't see why that is any different.  I also opened your MSG file in Notepad and searched for "English" and it didn't show up, so I am quite confused as to why a FileRead would work.....

Thanks

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

I also opened your MSG file in Notepad and searched for "English" and it didn't show up, so I am quite confused as to why a FileRead would work.....

 

i guess this is where encoding is (somehow) in effect - although i did try to open it in NotePad++ and played around with available encoding types there. that did not find it either...  :think:

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...