Sign in to follow this  
Followers 0
Olsenius

Help with notepad

4 posts in this topic

Hi.

I'm new to autoit, but have some very basic java experience, and i got this little problem i need to solve.

I got a folder with 10 .htm files (1.htm, 2.htm...)

I would like a script to open them in notepad and use the "find and replace" function.

I would like to change all "text1" to "text2", then save the file and move to next file in the same dir.

Any tips on how to do this would be apriciated.

Thx.

-Ols

Share this post


Link to post
Share on other sites



You could do this using AutoIt but it would be even easier to do it without Notepad.

  • Check out the FileFindFirstFile(), and FileFindNextFile() functions to get the names of the files.
  • Use the FileRead() and FileGetSize() functions to read each file's content into a variable.
  • Use StringReplace() to do the searching and replacing.
  • Use FileOpen(), FileWrite() and FileClose() to write the new versions back to the file.
  • While...WEnd will aid you in doing this for each file.
Good luck and we'll be here if you have any specific problems! :)

Share this post


Link to post
Share on other sites

Thank you this helped me alot.

I had to change the FileRead() to FileReadLine() so speed it up, but away from that its all perfect=).

I got a little more problem i cant solve now.

i got 1.htm, 2.htm... But want to expand it to unlimites number of files.

I use this to make it work on all the 1.htm - 10.htm files

--

$fila_i_tekst = StringReplace($fila_i_tekst, '1_', "||")

..

$fila_i_tekst = StringReplace($fila_i_tekst, '10_', "||")

then

$fila_i_tekst = StringReplace($fila_i_tekst, '<img src="||files/adfmd.gif">', "5")

--

Is it any way to make this work without adding those 10 lines?. like a search for '<img src=" *filename without .htm* _files/adfmd.gif">' and then replace. no matter if the filename is 100.htm that ill give "<img src="100_files/.. " in the source.

any help would be apriciated. thanks=)

And one thing more. is it any char for new line? when i write the entire string back to a new file its a long line, not so nice to read...

Thanks in advance.

-Ols

Share this post


Link to post
Share on other sites

Is it any way to make this work without adding those 10 lines?. like a search for '<img src="  *filename without .htm*  _files/adfmd.gif">' and then replace.  no matter if the filename is 100.htm that ill give "<img src="100_files/.. " in the source.

I think you might want the StringRegExpReplace() function for this. I hope that someone more well-versed in regular expressions can help you further.

And one thing more. is it any char for new line? when i write the entire string back to a new file its a long line, not so nice to read...

You can use FileWriteLine() instead of FileWrite() and a newline character will automatically be added; otherwise you could do something like --

fileWrite($theFile, $theData & @CRLF)

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