Sign in to follow this  
Followers 0
vladedoty

how do it use replace in notepad for multiple files

2 posts in this topic

#1 ·  Posted (edited)

Here's what i am trying to do is have this script search the script folder for all text files then open them up 1 by one and replace all occurrences of one word with the next and after the replaces, close the file and open the next and do the same thing til all have been edited.

i need help plz if someone is kind enough

here is the code

#Include <File.au3>
#Include <Array.au3>

$textTitle = "[REGEXPTITLE:.*Notepad.*]"

$search = FileFindFirstFile("*.*")
If $search == -1 Then Exit

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    ConsoleWrite("File: " & $file)
    ShellExecute($file, "", @ScriptDir)
    WinActivate($textTitle)
    $textHwnd = WinGetHandle($textTitle)
    ConsoleWrite(WinGetTitle($textHwnd))
    Sleep(2000)
    Send("!{E}")
    Send("{R}")
    Sleep(2000)
    ControlFocus($textHwnd, "", "[CLASS:Edit; INSTANCE:1]")
    ControlSend($textHwnd, "", "[CLASS:Edit; INSTANCE:1]", "chucknevermuck")
    Sleep(300)
    ControlFocus($textHwnd, "", "[CLASS:Edit; INSTANCE:2]")
    ControlSend($textHwnd, "", "[CLASS:Edit; INSTANCE:2]", "ckim111")
    Sleep(300)
    ControlFocus($textHwnd, "", "[CLASS:Button; INSTANCE:5]")
    ControlClick($textHwnd, "", "[CLASS:Button; INSTANCE:5]", "left", 1)
    WinClose($textHwnd)
    SendKeepActive("[REGEXPTITLE:\ANotepad\z]")
    Send("{Space}")
WEnd
Edited by vladedoty

Share this post


Link to post
Share on other sites



Hi vladedoty,

What I would recommend for this project is to construct an array of files (using your own function, file list to array or what not), then do the read (FileRead), replace (StringReplace/StringRegExpReplace) and the save the modified text (FileOpen with mode 2 = Overwrite mode, FileWrite (with reference to the previously opened file handle)).

So in pseudo code:

Construct Array of Files
For Each File:
    Read the contents
    StringReplace
    FileOpen
    FileWrite
    FileClose
End

Or something like that.

Give it a go and if you have any problems you know where to go. The helpfile, then the search, then post back here :(

Cheers,

Brett

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  
Followers 0