Jump to content

Recommended Posts

Posted

I like to do it like this but there are other ways. This returns what line it is on. Doing it line by line reduces the character amount in the buffer for stringinstr to check so I find it much better, but that is just a personal preference.

#include <File.au3>
$File = @ScriptDir & '\SomeFile.txt'
For $i = 1 To _FileCountLines($File)
    If StringInStr(FileReadLine($File,$i),'Some String of Text') Then MsgBox(0,'Here','Text is on line: ' & $i)
Next
Posted (edited)

Here is the code I am using:

$_DriveSet = DriveGetDrive("removable")
For $b = 1 To $_DriveSet[0]
                If $_DriveSet[$b] <> "a:" Then
                    If FileExists($_DriveSet[$b] & "\autorun.inf") Then
                ; MsgBox(0, "AutoTray", "Autorun.inf was found!")
                ; Start watching for autorun.inf files
                        Global $Name = $_DriveSet[$b] & '\autorun.inf'
                        $_File = FileOpen($Name, 0)
                        For $c = 1 To _FileCountLines($_File)
                            If StringInStr(FileReadLine($_File, $c), "[autorun]") Then MsgBox(0, "AutoTray", "Autorun header was found!")
                        Next
                    Else
                ; Message the user if autorun.inf doesn't exist
                        $_Cnt = MsgBox(0, "AutoTray", "Autorun.inf was not found to be in any removable devices.")
                    EndIf
                EndIf
            Next

However it doesn't find anything...

Edited by JamesB
Posted

Here is the code I am using:

$_DriveSet = DriveGetDrive("removable")
For $b = 1 To $_DriveSet[0]
                If $_DriveSet[$b] <> "a:" Then
                    If FileExists($_DriveSet[$b] & "\autorun.inf") Then
            ; MsgBox(0, "AutoTray", "Autorun.inf was found!")
            ; Start watching for autorun.inf files
                        Global $Name = $_DriveSet[$b] & '\autorun.inf'
                        $_File = FileOpen($Name, 0)
                        For $c = 1 To _FileCountLines($_File)
                            If StringInStr(FileReadLine($_File, $c), "[autorun]") Then MsgBox(0, "AutoTray", "Autorun header was found!")
                        Next
                    Else
            ; Message the user if autorun.inf doesn't exist
                        $_Cnt = MsgBox(0, "AutoTray", "Autorun.inf was not found to be in any removable devices.")
                    EndIf
                EndIf
            Next

However it doesn't find anything...

Try using _FileCountLines with the actual file, not handle of the file. So $Name
Posted

I cant, because it's a loop to find the drive letter.

What do you mean you can't ,

I made a file added, in [autorun] and some other junk then used this and it works just fine

Global $Name = @DesktopDir & '\some.txt'
                        $_File = FileOpen($Name, 0)
                        For $c = 1 To _FileCountLines($Name)
                            If StringInStr(FileReadLine($Name, $c), "[autorun]") Then MsgBox(0, "AutoTray", "Autorun header was found!")
                        Next

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
×
×
  • Create New...