AutoHotkey Community

It is currently May 26th, 2012, 8:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: August 3rd, 2005, 12:08 am 
First off, AutoHotKey is VERY slick. A lot of user-friendly stuff, especially the help.

For the wish: I use AutoHotKey mainly for running the multiple applications required in a convoluted compile process and I often am looking for a way to easily alter a text file with a regular expression search/replace so that I might be able to change around a .ini file depending on what I wanted to compiled and what the current state of the .ini file is.

I saw the the ability to read/write files, but no real way to manipulate them. I have a text editor that allows me to write a macro to do something similar and use AutoHotKey to trigger those macros after opening the appropriate files, but not everyone I work with has that editor, so they can't quite use that functionality.

It would be awesome to have it all wrapped neatly up in one sweet package that is AutoHotKey.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2005, 1:04 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Here are some things that might not be a complete solution, but can help a lot with file manipulation:

Regular expressions (RegEx): library and wrapper

File reading/writing loop

FileRead (reads the entire contents of a file into a variable).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2005, 7:09 pm 
Oh sweet, I'll definitely check these out. Thanks!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2005, 5:45 pm 
Yup the RegEx wrapper was exaclty what I was looking for:

Code:
SetMission(missionID)
{
   p:="^[^;].*mission.*"
   r:=";$0"
   FileDelete, C:\TEST\tmp.ini
   Loop, read, C:\TEST\test.ini, C:\TEST\tmp.ini
   {
      s:=A_LoopReadLine
      e:=RE_Replace(s,0,p,0,r)
      if (e>0)
         FileAppend, %s%`n
      Else
         FileAppend, %A_LoopReadLine%`n
   }

   p:=";(.*""" . missionID . """.*)"
   r:="$1"
   FileSetAttrib, -R, C:\TEST\test.ini
   FileDelete, C:\TEST\test.ini
   Loop, read, C:\TEST\tmp.ini, C:\TEST\test.ini
   {
      s:=A_LoopReadLine
      e:=RE_Replace(s,0,p,0,r)
      if (e>0)
         FileAppend, %s%`n
      Else
         FileAppend, %A_LoopReadLine%`n
   }
   
   FileDelete, C:\TEST\\tmp.ini

   return
}


Works like a charm. This is probably not the most efficient way to do things since I end up writing out a file twice, but this adds a ';' at the beginning of any line that contains the word 'mission' and doesn't already have a ';' at the beginning and then removes the ';' from the beginning of the mission line that was passed into the function.

Thanks!
Brian


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 7 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group