AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add text front of the line

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
0mega



Joined: 17 May 2007
Posts: 38

PostPosted: Tue Sep 16, 2008 8:19 pm    Post subject: Add text front of the line Reply with quote

Example:
!z::FileAppend , Text, Filename.txt

And if I moment later press exmp. !x it would add some text front of the line of textfile. Is it possible ?

It need add text front of line to latest row on textfile
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 726
Location: Calgary, AB, Canada

PostPosted: Tue Sep 16, 2008 8:41 pm    Post subject: Reply with quote

Look in Help for "FileReadLine". Read the last line, add your text to the front, then Re-Append it.
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Tue Sep 16, 2008 8:46 pm    Post subject: Reply with quote

If you need to do more things with a text file have a look at

Library for Text file manipulation
http://www.autohotkey.com/forum/topic32757.html
in your case you could use TotalLines() to get the
number of lines and ColPut() to add something to
the beginning of the last line.


Edit, Updated july 2009:
TF.ahk A Library for Text file manipulation
http://www.autohotkey.com/forum/viewtopic.php?t=46195
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum


Last edited by SoLong&Thx4AllTheFish on Thu Jul 23, 2009 5:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Tue Sep 16, 2008 8:52 pm    Post subject: Reply with quote

Code:
!z::
 FileDelete, FileName.txt
 FileAppend , Line1`nLine2`nLine3`nLine4`nLine5, Filename.txt
Return


!x::
 FileRead , Text, Filename.txt
 LengthOfText := StrLen( Text )
 LineFeedPosition := InStr( Text, "`n",0,0 )
 If not LineFeedPosition
    Return
 Prefix := SubStr( Text, 1, LineFeedPosition - 1 )
 Suffix := SubStr( Text, LineFeedPosition+1, LengthOfText-LineFeedPosition )
 NewText :=  Prefix "`n" A_Now "`n" Suffix
 MsgBox, % NewText
 FileDelete, FileName.txt
 FileAppend, %NewText%, FileName.txt
Return

_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
Omega
Guest





PostPosted: Wed Sep 17, 2008 5:04 pm    Post subject: Reply with quote

Thanks to all
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group