Jump to content

Find and replace


Dirk98
 Share

Recommended Posts

Guys, I need a piece of code that finds all files inside a folder, that meet certain name, extension and content criteria. For example, all "config.ini" files that contain "[Picture]" and replaces it with ";[Picture]". Can you please help me with this?

Much thanks,

Dirk.

Edited by Dirk98
Link to comment
Share on other sites

Some pseudocode...

_FileListToArray()

For $X = 0 to Array Length

FileOpen

FileRead

StringReplace ...

FileWrite

Next

Thank you very much, weaponx!

Now, those savvy, who, unlike me, can benefit from this tip: could you please merge it with what I requested above and post the result here?

Many thanks again.

Dirk.

Edited by Dirk98
Link to comment
Share on other sites

Because i'm a nice guy.

#include <File.au3>
;Define starting folder
$root = "C:\Documents and Settings\mjhorn\My Documents\TEMP"

;Create array of txt files
$theArray = _FileListToArray ($root, "*.txt",1)

;String to find
$find = "[Picture]"

;String to replace
$replace = ";[Picture]"

$resultString = "Replacing all occurences of " & $find & " with " & $replace & @CRLF

;Loop through array elements
For $X = 1 to $theArray[0]
    ;Replace all occurences
    $count = _ReplaceStringInFile($root & "\" & $theArray[$X],$find,$replace)
    If NOT @ERROR Then 
        $resultString &= $count & " occurences replaced in file: " & $root & "\" & $theArray[$X]
    EndIf
Next
    
MsgBox(0,"",$resultString)
Link to comment
Share on other sites

  • Moderators

@weaponx...

It's no wonder we have so many "Welcome to AutoIt, may we take your order" request lately.

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

We need to start a new website .... www.Rent-An-AutoIt-Coder.com.

Guess there's no real point to anyone learning anything here huh..... :P

Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

@weaponx...

It's no wonder we have so many "Welcome to AutoIt, may we take your order" request lately.

I like to give out a sample, then when they come back later they will be in such dire need they will have to offer up some kind of prior effort or else I'll hit them with "HELP FILE"

Link to comment
Share on other sites

  • Moderators

I like to give out a sample, then when they come back later they will be in such dire need they will have to offer up some kind of prior effort or else I'll hit them with "HELP FILE"

Hit'em Hard!

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

I like to give out a sample, then when they come back later they will be in such dire need they will have to offer up some kind of prior effort or else I'll hit them with "HELP FILE"

Ditto!!

I can still recall "Struggling" with learning this language, All I had ever done was some basic and some DOS applications previously. Even when people were kind enough to give me an example, I still had to study my ass-off to understand what it was doing and how to "bend it" into my desired out-come.

If it was not for those whom helped me in the beginning, I wouldn't be here today!

( Sorry Ron, you may have preferred that... lol)

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

weaponx has helped me, and so has Sm0ke and I appreciate it, sometimes its a relief to get some quick easy help, for me it was an encouragement to keep trying AutoIt out. And I can imagine that I speak for most noobs it is nice to get some "free" help every now and then, its a great forum, keep it up! :P

Link to comment
Share on other sites

  • Moderators

Ditto!!

I can still recall "Struggling" with learning this language, All I had ever done was some basic and some DOS applications previously. Even when people were kind enough to give me an example, I still had to study my ass-off to understand what it was doing and to "bend it" into my desired out-come.

If it was not for those whom helped me in the begining, I wouldn't be here today!

( Sorry Ron, you may have preferred that... lol)

8)

You guys totally misconstrued what I said.

The OP made an Order for Delivery.

He was given a direction to go in... And I'll bet my bottom dollar, as fast as he posted (14 minutes?????), he had no desire to even try and open the help file to learn what was presented to him/her.

With that said, I totally disagree with it, the reason you are where you are today in whatever language, is the effort you put forth yourself, not what others did for you.

Help is one thing, order taking is another!

Edited by SmOke_N
Added the last sentence.

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

I totally understand what you are saying Sm0ke and I was not disagreeing with what you or weaponx were saying.

It is different if someone comes in here expecting a handout and demands some code because they are new to AutoIt or just don't care to learn and want a quick answer and then are never heard from. That is until they want some more free code.

What I was trying to say is that it is nice to get help when starting out a new language. I don't expect to get spoon fed code to every problem I have but it sure is helpful when people mention the function needed and where it may go or give a link to some other similar code already mentioned in the forum.

There deffinitely is a difference between those 2 noobtypes.

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