Jump to content

Checking for words within a text file


Recommended Posts

I've read a number of threads over the past few days, including "http://www.autoitscript.com/forum/index.php?showtopic=47277". However, I've yet to figure out how to do what I'm trying to do.

What I'm looking to do is search for words (or small strings of words) within a file titled "backup.log" from drive "H:\". Example words would be "Desktop", "Favorites", etc. This is for a small app that will essentially do a quick check of the backup log that Microsoft's backup app creates, to confirm that it backed up a particular location.

Does anyone have any tips on how this could work, or could you point me to a thread that perhaps I'm missing due to the wrong criteria? Any help is appreciated!

Link to comment
Share on other sites

$File=FileRead("backup.log")
$res=StringInStr($File,"Desktop")
if $res=0 then 
    MsgBox(0,"Nope","String not found")
    Exit
EndIf
MsgBox(0,"Yup","We got one! It's at "&$res)oÝ÷ Ûú®¢×©ä²ØZ¶+¶W²Ú^­ú+)ಲí¡ûZ²L"¶.µê뢸§­"G©¶­¶)४ìz+,¹ë£¯z²7öh¶Ø§Ø^ë,j­«më-®)àÁ«'¢×èºwpéÈßÙ¥¢"§¶W×Ƕ­ÂÝ{az·Øb±Æ¬zØ^~)^Éhq«^u«GÓÝiÉ.¦Z nëm«]¡ë'ßÛlyé­¢f¤y§b}÷«zw§!éíz·ë¢ibíZºÚ"µÍÌÍÑ[OQ[TXY
    ][ÝÒÌLØXÚÝÙÉ][ÝÊ

Any ideas? I've tried this on two different systems with the same results. I am using the most recent version of AutoIT.

Thank you very much for your help thus far!

Link to comment
Share on other sites

Thanks, that is at least performing some sort of task without erroring out (I kept getting parse issues). However, I'm getting the message that the string was not found, when I'm looking in the file and can see that word in there. In this case the file is located at H:\backup.log, but that doesn't seem to make a difference when I enter from line 1:

$File=FileRead("H:\backup.log")oÝ÷ Ø ò×°ý½ëkçm+(Ü(v'ßz·§¶Ì¬µé¬Â+a¶¬jg«zË¥¶Âë"azj,¶·z{oz»"¢zëh!4ájy2¢ëÞ¯)®rè¯*.®¥¦Øn±ö«ßêº^&ë-¶ë.­ì¨¹ªÞ­æx-çâ觶»-¦VzØb±Ø¬¦V²²Ø^~*ì·]4r«iË^®Æ¬i׺ ²Æ y«­¢+ØÀÌØí¥±ôÅÕ½Ðí èÀäÈí­ÕÀ¹±½ÅÕ½Ðì(ÀÌØíÑô¥±I ÀÌØí¥±¤)5Í   ½à ØаÅÕ½ÐíÕÅÕ½Ðì°MÑÉ¥¹1Ð ÀÌØíÑ°ÄÀÀ¤¤)%MÑÉ¥¹%¹MÑÈ ÀÌØíÑ°ÅÕ½ÐíͭѽÀÅÕ½Ðì¤Q¡¸(5Í ½à ØаÅÕ½ÐíeÕÀÅÕ½Ðì°ÅÕ½Ðí]½Ð½¹ÌÌì%ÐÌäíÌÐÅÕ½ÐìµÀìÀÌØíÉÌÅÕ½Ðì¡ÉÑÉÌ¥¸¸ÅÕ½Ðì¤)¹%)5Í  ½à ÄØ°ÅÕ½Ðí9½ÁÅÕ½Ðì°ÅÕ½ÐíMÑÉ¥¹¹½Ð½Õ¹ÅÕ½Ðì

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

StringRegExp() will be much faster, especially if it's a huge file.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

StringRegExp() will be much faster, especially if it's a huge file.

And for the RegExp impaired (like me), here is...

Neogia's RegExp for Dummies.

...and Steve8tch's StrRegExpGUI.au3

...and the wiki-word on regular expressions

...and the 30 Minute RegEx Tutoial.

A RegEx tutorial (looks like an update of Neogia's) is now included in the help file for AutoIt. Look in the index under "String Regular expression".

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...