Jump to content
Sign in to follow this  
randeep

find?

Recommended Posts

randeep

hello all

i know it will be a stupid question, but as i am a newbie and not getting answer through 'Auto-it Help', so pls do reply.

i am having a .txt file. i want to add a text at the end of the text file (.txt), but if it is already exist then the window should close. if it is not having that particular text then the script will add it to the .txt file and then save it and then exit.

controlgettext not working as it is returning the whole text of the window, not that particular text.

pls help


[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
99ojo

Hi,

$file = FileOpen ("path\Mytextfile.txt", 1) ; open text file in append mode

$line = FileReadLine ($file, -1) ; read last line into $line

If StringInStr ($line, "MyTextToInsert") = 0 Then FileWriteLine ($file, "MyTextToInsert")

FileClose ($file)

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
randeep

not able to run it :D

Hi,

$file = FileOpen ("path\Mytextfile.txt", 1) ; open text file in append mode

$line = FileReadLine ($file, -1) ; read last line into $line

If StringInStr ($line, "MyTextToInsert") = 0 Then FileWriteLine ($file, "MyTextToInsert")

FileClose ($file)

;-))

Stefan


[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
99ojo

not able to run it :D

Hi,

not many hints to interprete. Please post error or code.

;-(

Stefan

Share this post


Link to post
Share on other sites
99ojo

hello stefan

here is the code, but it is returning nothing. pls place attached file at C:\.

#include <Process.au3>
;_RunDOS("Start Wordpad C:\OUT.TXT")

Local $file, $line
$file = _RunDOS("Start Wordpad C:\OUT.TXT");FileOpen ("C:\OUT.TXT", 1) ; open text file in append mode
ConsoleWrite("11")
$line = FileReadLine ($file, -1) ; read last line into $line
ConsoleWrite("22")
MsgBox(0, "", $line)
ConsoleWrite("33")
If StringInStr ($line, "1>") = 0 Then FileWriteLine ($file, "MyTextToInsert")
ConsoleWrite("44")
FileClose ($file)
ConsoleWrite("55")oÝ÷ Ûú®¢×R ¢Úk¡¹^ƬÁéeÂ+a­æx%jËew¢Ú4ß©bäázk nb±é©·-*.®­·b²«¨·X-ªê-jÙZ²Ùb䨶¢}Ê'v+b¢x¬m®éçx¯-Qzj/{X-~º&Ê«¢ëmÆÝ­¯+aÇ(u殶­sb6æ6ÇVFRfÇC¶fÆRæS2fwC°¤Æö6Âb33c¶fÆP¤FÒb33c¶ÆæP¥ôfÆU&VEFô'&gV÷C¶3¢b3#¶÷WBçGBgV÷C²Âb33c¶ÆæR²&VBfÆRçFò'&¤×6t&÷ÂgV÷C²gV÷C²Âb33c¶ÆæRµT&÷VæBb33c¶ÆæRÓÒ¤b7G&ætå7G"b33c¶ÆæRµT&÷VæBb33c¶ÆæRÓÒÂgV÷C³fwC²gV÷C²ÒFVâ b33c¶fÆRÒfÆT÷VâgV÷C´3¢b3#´õUBåEBgV÷C²Â²÷VâFWBfÆRâVæBÖöFP fÆUw&FTÆæRb33c¶fÆRÂgV÷C´×FWEFôç6W'BgV÷C² fÆT6Æ÷6Rb33c¶fÆR¤VæD

Share this post


Link to post
Share on other sites
randeep

@99ojo

the code below is not working well, it gives the output value that i want, for the first time only, then it automatically adds the text at the end of the window. :D i want to add text to the line 67 from below and delete the existing value. pls find the attached file.

#include <file.au3>
Local $file
Dim $line
_FileReadToArray ("C:\Create_job_wdog_subpresence.txt", $line) ; read File into array
MsgBox(0, "", $line [UBound ($line)-67])
If (StringInStr ($line [UBound ($line)-67], 'WHEN "PC3" THEN 1') = 0) Then
    $file = FileOpen ("C:\Create_job_wdog_subpresence.txt", 1) ; open text file in append mode
    FileWriteLine ($file, "MyTextToInsert")
    FileClose ($file)
EndIf
Edited by randeep

[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
November

Hi there,

Try this:

#include <Process.au3>
;_RunDOS("Start Wordpad C:\OUT.TXT")

Local $file, $line
$path = "C:\temp\OUT.TXT"
$file = _RunDOS("Start Wordpad " & $path);FileOpen ("C:\OUT.TXT", 1); open text file in append mode
ConsoleWrite("11")
$line = FileReadLine ($path, -1); read last line into $line
ConsoleWrite("22")
MsgBox(0, "", $line)
ConsoleWrite("33")
If StringInStr ($line, "1>") = 0 Then FileWriteLine ($file, "MyTextToInsert")
ConsoleWrite("44")
FileClose ($file)
ConsoleWrite("55")

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
randeep

No Effect :D

Hi there,

Try this:

#include <Process.au3> :( 
;_RunDOS("Start Wordpad C:\OUT.TXT")

Local $file, $line
$path = "C:\temp\OUT.TXT"
$file = _RunDOS("Start Wordpad " & $path);FileOpen ("C:\OUT.TXT", 1); open text file in append mode
ConsoleWrite("11")
$line = FileReadLine ($path, -1); read last line into $line
ConsoleWrite("22")
MsgBox(0, "", $line)
ConsoleWrite("33")
If StringInStr ($line, "1>") = 0 Then FileWriteLine ($file, "MyTextToInsert")
ConsoleWrite("44")
FileClose ($file)
ConsoleWrite("55")

Cheers


[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
November

Change path...

c:\out.txt and not c:\temp\out.txt

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
99ojo

@99ojo

the code below is not working well, it gives the output value that i want, for the first time only, then it automatically adds the text at the end of the window. :D i want to add text to the line 67 from below and delete the existing value. pls find the attached file.

#include <file.au3>
Local $file
Dim $line
_FileReadToArray ("C:\Create_job_wdog_subpresence.txt", $line) ; read File into array
MsgBox(0, "", $line [UBound ($line)-67])
If (StringInStr ($line [UBound ($line)-67], 'WHEN "PC3" THEN 1') = 0) Then
    $file = FileOpen ("C:\Create_job_wdog_subpresence.txt", 1) ; open text file in append mode
    FileWriteLine ($file, "MyTextToInsert")
    FileClose ($file)
EndIf

Share this post


Link to post
Share on other sites
randeep

@november

yes brother,

first thing i changed was path :D

but no effect :D

Change path...

c:\out.txt and not c:\temp\out.txt

Cheers

Edited by randeep

[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
November

Ok,

insert code and your needs, i'll try to help you better!

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
randeep

@99ojo

this wasn't clear since your last answer. You should more precise in what you want at the beginning of starting a thread.

actually, at starting this thread i gave a simple example, if changed then i was going to implement on the main script. :D

well you script is good, but is there any possibility that i can make change in the main script (Create_job_wdog_subpresence.txt) and not creating new one (Create_test.txt)????????

Edited by randeep

[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
99ojo

@99ojo

this wasn't clear since your last answer. You should more precise in what you want at the beginning of starting a thread.

actually, at starting this thread i gave a simple example, if changed then i was going to implement on the main script. :D

well you script is good, but is there any possibility that i can make change in the main script (Create_job_wdog_subpresence.txt) and not creating new one (Create_test.txt)????????

Hi,

just change

If $find = True Then

;FileDelete ("c:\Create_job_wdog_subpresence.txt")

$file = FileOpen ("c:\Create_test.txt",1)

to

If $find = True Then

FileDelete ("c:\Create_job_wdog_subpresence.txt")

$file = FileOpen ("c:\Create_job_wdog_subpresence.txt",1)

;-)) Stefan

Share this post


Link to post
Share on other sites
November

And this?

#include <Process.au3>
;_RunDOS("Start Wordpad C:\OUT.TXT")

Local $file, $line
$path = "C:\temp\OUT.TXT"
;$file = _RunDOS("Start Wordpad " & $path);FileOpen ("C:\OUT.TXT", 1); Using this the file is open and no append can be done, only using controlsend.
ConsoleWrite("11" & @CRLF)
$line = FileReadLine ($path, -1); read last line into $line
ConsoleWrite("22" & @CRLF)
;MsgBox(0, "", $line)
ConsoleWrite("33" & @CRLF)
$test = StringInStr ($line, "1>")
ConsoleWrite($test & @CRLF)
FileOpen($path, 1)
If $test > 0 Then 
    MsgBox(32, "Find", "Value : 1> was found in file")
Else
    FileWriteLine ($path, "MyTextToInsert");Changed the value to 1
    MsgBox(32, "Find", "Value : 1> was added to file")
EndIf
ConsoleWrite("44" & @CRLF)
FileClose ($file)
ConsoleWrite("55")

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
bogQ

i am having a .txt file. i want to add a text at the end of the text file (.txt), but if it is already exist then the window should close. if it is not having that particular text then the script will add it to the .txt file and then save it and then exit.

can i try? :Dif i didnot understand question correct then sry ^^

#include <Array.au3>
#include <file.au3>
Dim $aRecords
_FileReadToArray("test.txt",$aRecords)
$sSearch = "555" ;<== line text go heare
$iIndex = _ArraySearch($aRecords, $sSearch, 0, 0, 0, 1)
If @error Then
    $file = FileOpen("test.txt", 1)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    FileWrite($file,@CRLF&$sSearch)
    FileClose($file)
Else
;~     MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ".")
EndIf

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites
randeep

hello stefan

now i have added ur script to the functions below:

it demands for number of sites. then asks for name of site and then runs the scripts at the second function (no. of times entered in first function). but not able to run the ur script at the function 2.(but the window for name is coming). actually it is running but not editing in the script. :D

pls see where is prob.???

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Date.au3>
#include "Variable Declaration.au3"
#include <file.au3>

global $SubpresenceSubscribers

SubpresenceSubscribersWindow()

Func SubpresenceSubscribersWindow()

Opt('MustDeclareVars', 0)
;Opt("GUIOnEventMode",0)

Local $Input, $InputWindowHandle
Local $msg5, $SubmitButton

    $InputWindowHandle = GUICreate("Please Provide Input", 245, 140, -1, -1, $WS_EX_DLGMODALFRAME)
    GUICtrlCreateLabel("Please enter the number of Sites in network.", 20, 10)
    $Input = GUICtrlCreateInput("", 85, 60, 80, 0, $ES_NUMBER)
    $SubmitButton = GUICtrlCreateButton("Submit", 96, 87, 60)
    GUISetState();@SW_SHOW

    While 1

        $msg5 = GUIGetMsg()

        Select

            Case $msg5 = $SubmitButton
                $SubpresenceSubscribers = GUICtrlRead($Input)
                 GUIDelete()

                 ExitLoop

            Case $msg5 = $GUI_EVENT_CLOSE
                guidelete()
                ExitLoop

        EndSelect

    WEnd

    GUIDelete($InputWindowHandle)
    WinWaitClose("Please Provide Input")

EndFunc
;-----------------------------------------------------------------------------------------------------

SubscriberNameWindow()

;-----------------------------------------------------------------------------------------------------

Func SubscriberNameWindow()

    Local $msg6
    Local $OkButton
    Local $TotalSubscribers, $SubpresenceInput, $SubscriberName

    Do

        $TotalSubscribers = $TotalSubscribers + 1
    Until $TotalSubscribers =$SubpresenceSubscribers

    For $TotalSubscribers =$SubpresenceSubscribers To 1 step -1

            GUICreate("Please Provide Name", 220, 140, -1, -1, $WS_EX_DLGMODALFRAME)
            gUICtrlCreateLabel("Please enter the name of Subscriber.", 20, 10)
            $SubpresenceInput = GUICtrlCreateInput("", 70, 50, 80, 0)
            $OkButton = GUICtrlCreateButton("OK", 82, 80, 60)
            GUISetState()

            While 1

                $msg6 = GUIGetMsg()

                    Select

                        Case $msg6 = $OkButton
                            $SubpresenceName = GUICtrlRead($SubpresenceInput)
                            ;guidelete()
                            ExitLoop

                        Case $msg6 = $GUI_EVENT_CLOSE
                            Exitloop

                    EndSelect

            WEnd

        GUIDelete()
        WinWaitClose("Please Provide Name")

        ;-------------------------------------------------------------------------------
        Local $file
        Dim $line

        $find = False
        _FileReadToArray ("C:\Create_job_wdog_subpresence.sql", $line) ; read File into array
        For $i = 1 To UBound ($line) -1
            If (StringInStr ($line [$i], "TESTSITENAME") <> 0) Then
                $line [$i] = $SubpresenceName
                $find = True
                ExitLoop
            EndIf
        Next

        If $find = True Then
            FileDelete ("C:\Create_job_wdog_subpresence.sql")
            $file = FileOpen ("C:\Create_job_wdog_subpresence.sql",1)
            For $i = 1 To UBound ($line) - 1
                FileWriteLine ($file, $line [$i])
            Next
            FileClose ($file)
        EndIf

    Next

EndFunc
Edited by randeep

[font="Palatino Linotype"]Randeep Singh[/font][sub][/sub]

Share this post


Link to post
Share on other sites
99ojo

hello stefan

now i have added ur script to the functions below:

it demands for number of sites. then asks for name of site and then runs the scripts at the second function (no. of times entered in first function). but not able to run the ur script at the function 2.(but the window for name is coming). actually it is running but not editing in the script. :D

pls see where is prob.???

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Date.au3>
#include "Variable Declaration.au3"
#include <file.au3>

global $SubpresenceSubscribers

SubpresenceSubscribersWindow()

Func SubpresenceSubscribersWindow()

Opt('MustDeclareVars', 0)
;Opt("GUIOnEventMode",0)

Local $Input, $InputWindowHandle
Local $msg5, $SubmitButton

    $InputWindowHandle = GUICreate("Please Provide Input", 245, 140, -1, -1, $WS_EX_DLGMODALFRAME)
    GUICtrlCreateLabel("Please enter the number of Sites in network.", 20, 10)
    $Input = GUICtrlCreateInput("", 85, 60, 80, 0, $ES_NUMBER)
    $SubmitButton = GUICtrlCreateButton("Submit", 96, 87, 60)
    GUISetState();@SW_SHOW

    While 1

        $msg5 = GUIGetMsg()

        Select

            Case $msg5 = $SubmitButton
                $SubpresenceSubscribers = GUICtrlRead($Input)
                 GUIDelete()

                 ExitLoop

            Case $msg5 = $GUI_EVENT_CLOSE
                guidelete()
                ExitLoop

        EndSelect

    WEnd

    GUIDelete($InputWindowHandle)
    WinWaitClose("Please Provide Input")

EndFunc
;-----------------------------------------------------------------------------------------------------

SubscriberNameWindow()

;-----------------------------------------------------------------------------------------------------

Func SubscriberNameWindow()

    Local $msg6
    Local $OkButton
    Local $TotalSubscribers, $SubpresenceInput, $SubscriberName

    Do

        $TotalSubscribers = $TotalSubscribers + 1
    Until $TotalSubscribers =$SubpresenceSubscribers

    For $TotalSubscribers =$SubpresenceSubscribers To 1 step -1

            GUICreate("Please Provide Name", 220, 140, -1, -1, $WS_EX_DLGMODALFRAME)
            gUICtrlCreateLabel("Please enter the name of Subscriber.", 20, 10)
            $SubpresenceInput = GUICtrlCreateInput("", 70, 50, 80, 0)
            $OkButton = GUICtrlCreateButton("OK", 82, 80, 60)
            GUISetState()

            While 1

                $msg6 = GUIGetMsg()

                    Select

                        Case $msg6 = $OkButton
                            $SubpresenceName = GUICtrlRead($SubpresenceInput)
                            ;guidelete()
                            ExitLoop

                        Case $msg6 = $GUI_EVENT_CLOSE
                            Exitloop

                    EndSelect

            WEnd

        GUIDelete()
        WinWaitClose("Please Provide Name")

        ;-------------------------------------------------------------------------------
        Local $file
        Dim $line

        $find = False
        _FileReadToArray ("C:\Create_job_wdog_subpresence.sql", $line) ; read File into array
        For $i = 1 To UBound ($line) -1
            If (StringInStr ($line [$i], "TESTSITENAME") <> 0) Then
                $line [$i] = $SubpresenceName
                $find = True
                ExitLoop
            EndIf
        Next

        If $find = True Then
            FileDelete ("C:\Create_job_wdog_subpresence.sql")
            $file = FileOpen ("C:\Create_job_wdog_subpresence.sql",1)
            For $i = 1 To UBound ($line) - 1
                FileWriteLine ($file, $line [$i])
            Next
            FileClose ($file)
        EndIf

    Next

EndFuncoÝ÷ Ûú®¢×'hmz0{¶°êÞËazènW¦nër¢ëÛajÛayû§rب+jY^u*-êk¡¹^h ÖÞ¶­¶¢}Ê'v+b¢t­®)à"t­­Ú²}ýµø§vØ^«ôߤ®nÞ±éÜxÖ¦z+-ëæ¬LDHÄ4Jè­×º
ÞjÊ'ë-¦ëZÈ£§¶¢~ËZµéÖ®¶­sdb7G&ætå7G"b33c¶ÆæR²b33c¶ÒÂgV÷CµDU5E4DTäÔRgV÷C²fÇC²fwC²FVà¢×6t&÷ÂgV÷C²gV÷C²Â7G&ætå7G"b33c¶ÆæR²b33c¶ÒÂgV÷CµDU5E4DTäÔRgV÷C²fײ5$Äbfײb33cµ7V'&W6Væ6TæÖR¢b33c¶ÆæR²b33c¶ÒÒb33cµ7V'&W6Væ6TæÖP

so you could see, that the if condition is running and $find is set to TRUE. Also you see the variable $SubpresenceName.

You may check as well if the sql file is write protected.

;-))

Stefan

P.S: For better analysis and overview you should write code like:

includes

Variables

Function1 ()

Function2 ()

Func Function1 ()

EndFunc

Func Function2 ()

EndFunc

Edited by 99ojo

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.