Jump to content

Recommended Posts

Posted

Hey guys,

I am having an issue with a new project where I want to search through a file, line by line to find certain words / text. Once finding that text I want to delete or do whatever with it. There is a certain function that is not working, I am sure this is because of my confusion with the language and not understanding correctly. Please can someone have a look at the DeleteLines() function and give suggestions?

CODE

;===================================================================================================

;

; Program: To search through text file & remove ;

; certain text specified then when done sleep ;

; Author: Colin Jeffery ;

; ;

; Date: 15th April 2006 ;

; ;

; 1. If program Scite.exe is not running, run it ;

; 2. Search the folder MyDocuments\PDFConversion\ for all text files and return what you find ;

; 3. Run the text file found ;

; 4. Search line by line for certain text / words and then delete them if found ;

;===================================================================================================

;

#include <GuiConstants.au3>

#include <Array.au3>

#include <File.au3>

Opt ("TrayIconDebug", 1)

Opt ("GuiOnEventMode", 0)

Opt ("GuiCloseOnEsc", 1)

opt ("TrayMenuMode", 0)

;~Variables~;

$title1 = ProcessExists("Scite.exe")

$search = FileFindFirstFile(@MyDocumentsDir & "\PDFConversion\*.txt")

$result = FileFindNextFile($search)

;~Calling Functions~;

CheckScite()

ChangeTxtName()

DeleteLines()

;Test()

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

;~Functions~;

Func CheckScite(); Check to see if Scite is running and if not run it.

If $title1 = 0 Then

Scite()

;~ Else

;~ If $title1 <> 0 Then

;~ MsgBox(64, "Warning", "Process is already running",)

;~ EndIf

EndIf

EndFunc

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

Func Scite(); Run Scite

Run("Scite.exe", "E:\Program Files\AutoIt3\SciTe\SciTe.exe", @SW_Maximize)

EndFunc

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

Func ChangeTxtName()

FileCopy(@MyDocumentsDir & "\PDFConversion\" & $result, @MyDocumentsDir & "\PDFConversion\ConvertingPDF.txt",1)

EndFunc

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

Func DeleteLines()

$file = FileOpen("ConvertingPDF.txt", 0)

$refer = StringLeft("Refer", 5)

$line = 1

If $file = -1 Then

MsgBox(64, "Error", "Unable to open file.")

Exit

EndIf

While 1

If @error = -1 Then ExitLoop

$readline = FileReadLine("ConvertingPDF.txt", $line)

If $readline = $refer Then

FileWriteLine($file, $line)

;Send("{LSHIFT}+{END}+{DEL}",)

EndIf

$line = $line + 1

Wend

FileClose($file)

EndFunc

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

Func Test()

MsgBox(64,"Test Result", $result, 5)

EndFunc

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Posted

Hi,

maybe try this.

Func _replace()
$find = "0"
$replace = "X"
$filename = @MyDocumentsDir & "\PDFConversion\ConvertingPDF.txt"
$retval = _ReplaceStringInFile($filename,$find,$replace)
if $retval = -1 then
    msgbox(0, "ERROR", "The pattern could not be replaced in file: " & $filename & " Error: " & @error)
    exit
else
    msgbox(0, "INFO", "Found " & $retval & " occurances of the pattern: " & $find & " in the file: " & $filename)
endif
EndFunc

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted

Something like this. Should delete any lines in a file with whatever you have the $refer variable set to.

#include <File.au3>
DeleteLines()

Func DeleteLines()
$file = FileOpenDialog("Open Text File",@ScriptDir, "Text (*.txt)")
$refer = "refer"
$line = 1

If $file = -1 Then
MsgBox(64, "Error", "Unable to open file.")
Exit
EndIf

While 1
$readline = FileReadLine($file,$line)
If @error = -1 Then ExitLoop 
StringInStr($readline,$refer)
If @error <> 1 Then
_FileWriteToLine($file, $line, "", 1)
EndIf
$line = $line + 1
Wend

FileClose($file)
MsgBox(0, "Done", "Finished replacing text!")
EndFunc
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Posted

result from trying this was

C:\Program Files\AutoIt3\beta\Examples\Helpfile\_ReplaceStringInFile.au3(17,56) : ERROR: _ReplaceStringInFile(): undefined function.
$retval = _ReplaceStringInFile($filename,$find,$replace)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Hi,

maybe try this.

Func _replace()
$find = "0"
$replace = "X"
$filename = @MyDocumentsDir & "\PDFConversion\ConvertingPDF.txt"
$retval = _ReplaceStringInFile($filename,$find,$replace)
if $retval = -1 then
    msgbox(0, "ERROR", "The pattern could not be replaced in file: " & $filename & " Error: " & @error)
    exit
else
    msgbox(0, "INFO", "Found " & $retval & " occurances of the pattern: " & $find & " in the file: " & $filename)
endif
EndFunc

So long,

Mega

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Posted

are you including string.au3?

add

#include <string.au3>

to the top of ur script

Thank you that worked, though now I am having another issue. I will post when i get home :think:

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

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...