Available Functions
*1: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.
*2: TF_Count does not support files and only works with variables.
Deprecated (but still working)
TF: Textfile & String Library for AutoHotkey [lib]
Version: 3.3
last update:
16 April 2010
- see History.
Library: http://www.autohotkey.net/~hugov/tf.ahk
Forum: http://www.autohotkey.com/forum/viewtopic.php?t=46195
Examples: http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363
As the name suggest this is a AHK Library with a number of functions to "manipulate" text, both files such as *.txt, *.ahk, *.html, *.css etc AND Strings (or variables). For example you can delete specific lines, replace words or specific lines, number lines, remove or insert columns of text, etc. See the list of functions on the right for a complete overview.
It is not useful for binary files or data such as MS Office files, PDFs, EXEcutables, images etc. (Tip: search the AHK forum for "binread" to find some pointers on how to read, write and "edit" binary files.)
Concept
It is important to understand a few basic concepts before you start working with the TF library:
To understand how to work with files and variables please read the "Textfile and the ! Prefix" and "Files & Variables" sections below.
You can either place TF.ahk in your LIB directory (see http://www.AutoHotkey.com/docs/Functions.htm#lib) or use #include (see http://www.AutoHotkey.com/docs/commands/_Include.htm)
You can find examples of most functions in the "example script" here http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363
Note: Because most of these functions operate on a line by line basis they WILL be slower than if you write your own functions or script which could operate on an entire file or variable at once. Keep this in mind if you need to process many files/variables or very large files/variables in case speed is an issue.
Alternatives
If you want to use similar functions in batch files try some of these programs:
Almost all functions accept the following basic parameters:
Text | The Filename (may include (absolute) path) to read from and save to (for all functions that write an output file). Note: by default a filename_copy will be created, use the ! prefix if you want to OverWrite the TextFile (e.g. the source file) As of v3 "Text" can also be a variable or indeed text directly passed on to the function. See Textfile and the ! Prefix. |
! Prefix | If Text starts with ! (eg:
"!c:\sample.txt") it will overwrite the text file, otherwise it will
save the new file to a copy of the text file eg: Filename_copy.txt (All,
apart from reading functions because there is no output file) Tip: you can use concatenation to add the !, e.g. "!" . Filename.txt, see the examples in the AHK thread. Note: If Text is a variable, it can start with a ! as TF will detect automatically that it is not a file and will therefore not create a file but return the altered variable instead. See Textfile and the ! Prefix. |
Lines | Number of lines to read |
StartLine | Start of Range (Almost all). See (StartLine, Endline) Syntax. |
EndLine | End of Range (Almost all). See (StartLine, Endline) Syntax. |
SearchText | Text to Find (Find / Replace functions) |
ReplaceText | Text to Replace (Find / Replace functions) |
Next to the ones above many functions have speficic parameters explained below with the description of each function.
Backup files: If a subdirectory "backup" is present in the directory of TextFile a backup is made before overwriting the original file (both for file.txt and file_copy.txt) with the BAK extention
You can find examples of most functions in the "example script" here http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363
(StartLine, Endline) Syntax
You can pass on multiple lines (sections) by using the StartLine parameter.
Examples:
Incremental (EndLine will not be ignored)
Textfile and the ! Prefix
Valid examples for using a Textfile:
TF_("file.txt", .... ; Process file.txt and write output to file_copy.txt F=file.txt ; ; Note how F is a variable, but AHK/TF will see it is meant to represent file.txt and write output to file_copy.txt TF_(F, .... ; Process file.txt and write output to file_copy.txt TF_("!file.txt", .... ; Process file.txt and overwrite file.txt F=file.txt TF_("!" . F, .... ; Process file.txt and overwrite file.txt F=!file.txt TF_(F, .... ; Process file.txt and overwrite file.txt In a Loop, FilePattern: TF_(A_LoopFileName, .... ; Process file and write output to file_copy TF_("!" . A_LoopFileName, .... ; Process file and overwrite file Loop, *.txt { TF_(A_LoopFileName, .... ; Process file and write output to file_copy }
If you want to use multiple TF functions on a single file it is advised to use the ! Prefix
F=!file.txt TF_RemoveBlankLines(F) ; remove all empty lines from file.txt and overwrite original file.txt TF_LineNumber(F) ; add linenumbers to all lines and overwrite original file.txt TF_Replace(F, "this", "that") ; Replace the word "this" with "that" and overwrite original file.txt ; So the original file.txt has undergone three changes
Files & Variables (v3+)
The new concept of variables (while keeping backward compatibility with the TF lib that only accepted files) is probably best illustrated by some easy examples.
NEW as of v3: TF()
In order to save you the trouble of using a fileread to read a file into a variable and proceed to use various TF functions there is the TF() Function.
TF("pathtofile", CreateGlobalVar="T")
By default it reads the contents of the file in a global variable named t and returns it
for further processing. By default it creates variable t if a variable name is omitted
so if you do not like to use t you can use anything you like. It is NOT mandatory to use
TF(), you are welcome to use a fileread as well, TF() is merely added for convenience
as we will see in the examples below.
Repeat: You only have to use TF() if you want to read a file into a variable and use it on multiple TF_* Functions.
TF() Examples:
TF("file.txt") ; will create global var t TF("file.txt", "MyVar") ; will create global var MyVarExamples on how to use files & variables with TF:
#Include tf.ahk TestFile= ; create variable (join`r`n 1 Hi this 2 a test variable 3 to demonstrate 4 how to 5 use this 6 new version 7 of TF.AHK ) FileDelete, TestFile.txt FileAppend, %TestFile%, TestFile.txt ; create file F=TestFile.txt ; just a shorthand code for TextFile.txt, so below when ; using F we are still passing on a TextFile, not a variable ;pass on file, read lines 5 to end of file: MsgBox % "From File 1:`n" TF_ReadLines("TestFile.txt",5) ; same as before MsgBox % "From File 2:`n" TF_ReadLines(F,5) ; same as before ;pass on variable, read lines 1 to 5 MsgBox % "From Variable 1:`n" TF_ReadLines(TestFile,"1-5") MsgBox % "From Variable 2:`n" TF_ReadLines("Hi`nthis`nis`na`ntest`nvariable`nfor`ntesting",1,3) ; pass on string ;Examples using TF(): (it will save you a FileRead if you want to work with Variables TF("TestFile.txt") ; read file, create globar var t t:=TF_ReadLines(t,5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t MsgBox % "TF(), example 1:`n" t TF("TestFile.txt", "MyVar") ; read file, create globar var MyVar MyVar:=TF_ReadLines(MyVar,5) ; pass on global var MyVar created by TF(), read lines 5 to end of file, asign result to MyVar MsgBox % "TF(), example 2:`n" MyVar ; Note how we can use TF() here t:=TF_ReadLines(TF("TestFile.txt"),5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t MsgBox % "TF(), example 3:`n" t MyVar:=TF_ReadLines(TF("TestFile.txt","MyVar"),5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t MsgBox % "TF(), example 4:`n" MyVar t:=TF_ReadLines(TF(F),5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t t:=TF_ReverseLines(t,5) ; pass on global var t created by TF(), reverse lines, asign result to t MsgBox % "TF(), example 5:`n" t ; Work directly with the clipboard or another other variable Clipboard=Line 1`nLine 2`nLine 3`nLine 4`nLine 5`nLine 6`nLine 7`nLine 8 Clipboard:=TF_RemoveLines(Clipboard, 3, 6) ; remove lines 3 to 6 MsgBox % "Clipboard, example 6:`n" ClipboardTF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.
Common mistake(s):
MyVar:=TF_ReadLines("TestFile.txt"),5) ; this is wrong. It is AN INCORRECT EXAMPLE!
The example above is incorrect: You pass on a file so the output is testfile_copy.txt. In this case nothing meaningful is assigned to the variable MyVar. Correct would be:
MyVar:=TF_ReadLines(MyVar,5) ; this is OK
MyVar:=TF_ReadLines(TF("TestFile.txt","MyVar"),5) ; this is OK
This library is based on the Library for Text file manipulation started by Heresy. I have contributed a number of functions to that library, but that version also has some "bugs" which are hopefully resolved in this TF library. [Heresy seems to have dropped off the radar so the original library can not be updated at the moment.]
Thanks to: Heresy, SKAN! (countlines, setwidth, spaces), Olegbl (suggestion for find*), infogulch (suggestion for tab <-> spaces), Murp|e (suggestions for documentation, check if file exists), ribbet.1 (New features in TF_LineNumber), Tuncay (help with TF() and borrowed ideas for TAIL), Guys (and Girls?) at Ask for Help, [maybe forget someone?], AHK artwork: Philou
Note: Some of these function are very similar but they are included for ease of use ...
You can find examples of most functions in the "example script" here http://www.autohotkey.com/forum/viewtopic.php?p=280363#280363
TF(TextFile, CreateGlobalVar="T")
Note: see background info and examples above at Files and Variables.
TF_CountLines(Text)
MsgBox % TF_CountLines("File.txt") ; show the number of lines of file in a MsgBox Lines:=TF_CountLines("File.txt") ; store the number of lines of file in a variable
TF_Count(String, Char)
Notes: do not use it to count lines (`n) because that will return an incorrect value, hence TF_CountLines.
TF_Count does not support files and only works with variables.
MsgBox % TF_Count("Hello this is an example", "i") ; count how many i's there are in the string
TF_ReadLines(Text, StartLine = 1, EndLine = 0, RemoveTrailing = 0)
Note: by default it will add a newline character to the lastline, so if you want to append new data to the readlines or you don't have to start it with a newline char. If you don't want that use RemoveTrailing = 1.
MsgBox % TF_ReadLines("File.txt",5) ; Read lines 5 to end of file, show result in a MsgBox Lines:=TF_ReadLines("File.txt",5) ; Read lines 5 to end of file, store result in variable MsgBox % TF_ReadLines("File.txt",5,0,1) ; 0 for end line indicates until end of file, remove trailing empty line.
TF_Tail(Text, Lines = 1, RemoveTrailing = 0, ReturnEmpty = 1)
Notes:
MsgBox % TF_Tail("File.txt", 3) ; get the last three lines MsgBox % TF_Tail("File.txt", -2) ; get second to last line, negative values only return one line MsgBox % TF_Tail("File.txt", 5, 0, 0) ; return the last five lines, with trailing new line and excluding empty lines
TF_Replace(Text, SearchText, Replacement="")
TF_Replace("File.txt","key","lock") ; pass on file, replace the word "key" with "lock" in file
TF_ReplaceInLines(Text, StartLine = 1, EndLine = 0, SearchText = "", ReplaceText = "")
TF_ReplaceInLines("!File.txt","1,3,9","","key","lock") ; overwrite file, replace key with lock in lines 1 3 and 9
TF_RegExReplace(Text, NeedleRegEx = "", Replacement = "")
TF_RegExReplace("File.txt","im)^(.*)$","[$1]") ; pass on file, wrap all lines in []
TF_RegExReplaceInLines(Text, StartLine = 1, EndLine = 0, NeedleRegEx = "", Replacement = "")
TF_RegExReplaceInLines("File.txt",3,8," [a-z]{3} "," lock ") ; replace any three letter word with lock in lines 3 to 8
TF_RemoveLines(Text, StartLine = 1, EndLine = 0)
TF_RemoveLines("File.txt", 5, 10) ; remove lines 5 to 10 from file
Note: If you pass on a negative value for StartLine, example TF_RemoveLines(Text, -5, .... it will remove these lines from the end of Text, so -5 will remove the last five lines. The EndLine parameter is ignored.
TF_RemoveBlankLines(Text, StartLine = 1, EndLine = 0)
Note: also removes lines with only tabs & spaces e.g. "white space"
TF_RemoveBlankLines("File.txt") ; remove blanklines in entire file
TF_RemoveDuplicateLines(Text, StartLine = 1, Endline = 0, Consecutive = 0, CaseSensitive = false)
TF_RemoveDuplicateLines("File.txt","","",1,false) ; remove only Consecutive duplicate lines
TF_InsertLine(Text, StartLine = 1, Endline = 0, InsertText = "")
TF_InsertLine("File.txt","2,4,9",5,"---") ; insert --- in lines 2 4 and 9. 5 is endline will be ignored
TF_ReplaceLine(Text, StartLine = 1, Endline = 0, ReplaceText = "")
TF_ReplaceLine("File.txt","1+3",8,"---") ; replace lines 1 4 and 7. 8 is end line so no more lines are processed after
TF_InsertPrefix(Text, StartLine = 1, EndLine = 0, Text = "")
TF_InsertPrefix("File.txt",5,8, "Hello ") ; Prefix Hello in lines 5 to 8
TF_InsertSuffix(Text, StartLine = 1, EndLine = 0 , Text = "")
TF_InsertSuffix("File.txt","2-4,6-9","", " Hello") ; Suffix Hello in lines 2 to 4 and 6 to 9
TF_TrimLeft(Text, Count = 1, StartLine = 1, EndLine = 0)
TF_TrimLeft("File.txt","","",25) ; Trim Left 25 Characters all lines
TF_TrimRight(Text, Count = 1, StartLine = 1, EndLine = 0)
TF_TrimRight("File.txt","4,6,8","",45) ; Trim Right 45 Characters in lines 4 6 and 8
TF_AlignLeft(Text, StartLine = 1, EndLine = 0, Columns = 80, Padding = 0)
Note: Using the Align functions will not take into account any leading or trailing spaces a line had BEFORE processing. So all white space before and after the text is removed before the text is aligned.
Padding = 0 Remove trailing white space Padding = 1 Keep trailing white space
TF_AlignLeft("File.txt","","",90, 1) ; AlignLeft all lines, keep trailing white space
TF_AlignCenter(Text, StartLine = 1, EndLine = 0, Columns = 80, Padding = 0)
Note: Using the Align functions will not take into account any leading or trailing spaces a line had BEFORE processing. So all white space before and after the text is removed before the text is aligned.
Skip = 0 process empty lines, fill with spaces Skip = 1 skip empty lines, do not fill with spaces
TF_AlignCenter("File.txt","","",150, 1) ; AlignCenter, all lines skip emtpy lines, do not fill with spaces
TF_AlignRight(Text, StartLine = 1, EndLine = 0, Columns = 80, Skip = 0)
Note: Using the Align functions will not take into account any leading or trailing spaces a line had BEFORE processing. So all white space before and after the text is removed before the text is aligned.
Skip = 0 process empty lines, fill with spaces Skip = 1 skip empty lines, do not fill with spaces
TF_AlignRight("File.txt","","", 190, 0) ; AlignRight, all lines, do not skip emtpy lines fill them with spaces
TF_LineNumber(Text, Leading = 0, Restart = 0, Char = 0)
Leading = 0 No padding with leading zeros Leading >= 1 Include padding with leading zeros (001 v 1) Restart = restart counter after X lines (starting again at 1) Char = character to use for leading/padding. Default 0, but can be any character. Tip: use a space.
TF_LineNumber("File.txt",1,15,A_Space) ; Add linenumbers, padding with spaces, linenumbers are aligned right because of space
TF_ConCat(FirstTextFile, SecondTextFile, OutputFile, Blanks = 0, FirstPadMargin = 0, SecondPadMargin = 0)
Based on: CONCATenate text files, ftp://garbo.uwasa.fi/pc/ts/tsfltc22.zip
With TF_ConCat you can join Text files side by side.
Blanks is number of blanks between lines
You can pad blanks the right margin of either of the text files, for this use FirstPadMargin and SecondPadMargin.
TF_ColGet(Text, StartLine = 1, EndLine = 0, StartColumn = 1, EndColumn = 1, Skip = 0)
Note: A TAB character is 1 character so for files with TABS the column might not be where you expect it to be skip = 0, DO NOT skip lines shorter then startcolumn position skip = 1, skip lines shorter then startcolumn position
TF_ColGet("File.txt","","",2,13) ; get columns 2 to 13 from all lines, so it removes all other columns from the file or variable
TF_ColPut(Text, Startline = 1, EndLine = 0, StartColumn = 1, Text = "", Skip = 0)
Based on: COLPUT.EXE & CUT.EXE, ftp://garbo.uwasa.fi/pc/ts/tsfltc22.zip
Note: A TAB character is 1 character so for files with TABS the column might not be where you expect it to be skip = 0, DO NOT skip lines shorter then startcolumn position skip = 1, skip lines shorter then startcolumn position
TF_ColPut("File.txt","","",5, "|", 0) ; insert | in column 5 of all lines including empty lines (= | will be at column 1)
TF_ColCut(Text, StartLine = 1, EndLine = 0, StartColumn = 1, EndColumn = 1)
Based on: COLPUT.EXE & CUT.EXE, ftp://garbo.uwasa.fi/pc/ts/tsfltc22.zip
TF_ColCut("File.txt", "2+2", "", 4, 38) ; remove columns 4 to 38 in lines 2 4 6 8 etc
TF_ReverseLines(Text, StartLine = 1, EndLine = 0)
Note: Startline parameter can not use specific lines, sections or incremental here
TF_ReverseLines("File.txt",2,9) ; reverse lines 2 to 9
TF_Find(Text, StartLine = 1, EndLine = 0, SearchText = "", ReturnFirst = 1, ReturnText = 0)
TF_Find(Lines) compatibility notes as of v3.1:
- Because the old TF_Find(Lines) did not use RegExMatch you may need to rewrite some of your
SearchText parameters. This means that if you used "special" characters which have
a special meaning in a RegEx: \.*?+[{|()^$ they must be preceded by a backslash to be seen as literal.
For example, \. is a literal period and \\ is a literal backslash. Escaping can be
avoided by using \Q...\E. For example: \QLiteral Text\E.
See http://www.autohotkey.com/docs/commands/RegExMatch.htm
for further information.
- The CaseSensitive parameter has been dropped, if you used that you must update your
call to TF_Find(Lines)
ReturnFirst = 0 return multiple lines ReturnFirst = 1 return first line only ReturnText = 0 return line numbers only ReturnText = 1 return entire line (text). This simulates a basic grep feature ReturnText = 2 return line numbers + entire line (text). This simulates a basic grep feature
MsgBox % TF_Find("File.txt", "", "", "keys") ; return first line number with keys in it MsgBox % TF_Find("File.txt", "", "", " c[a-z]+s ", 0, 1) ; find all lines with words that start with a c an end with an s
TF_SplitFileByLines(Text, SplitAt, Prefix = "file", Extension = "txt", InFile = 1)
SplitAt = Number of lines (three methods, see below) Prefix . Extension = filenameAUTOINCREMENT.Extension (Example: part_ . txt) InFile = 0 skip line e.g. do not include the actual line in any of the output files InFile = 1 include line IN current file InFile = 2 include line IN next file
Note: If you pass on a variable to TF_SplitFileByLines, the array size will be returned
as Prefix0 and the array elements as Prefix1, Prefix2 etc similar to the AHK StringSplit command.
The Extention parameter is ignored when using variables.
Some characters are illegal such as - + @ % & * _ \ / [ ] etc to use in Prefix, stick to a-z A-Z.
Options for "SplitAt" parameter:
a) One numerical value, example TF_SplitFileByLines(Text, "25", .... will split text every 25 lines until the end b) Split at rotating line lengths using a dash "-" as separator, example TF_SplitFileByLines(Text, "5-10-15", .... will split text at 5 10 15 lines, until the end so 5 lines, 10 lines, 15 lines, 5 lines, 10 lines etc c) Split at specific lines using a comma "," as separator, example TF_SplitFileByLines(Text, "5,81,135", .... will split text at lines 5,81,135 until end of file (e.g. last file will be from line 135 until the end)
TF_SplitFileByLines("File.txt", 2, "part", "zec", 1) ; split source file every 2 lines, include 2nd line INFILE ;illlustrate use of variables and returned arrays: TF_SplitFileByLines(Variable, 2, "part", "zec", 1) MsgBox % "Array size: " . Part0 . "`n1st array element: " Part1
TF_SplitFileByText(Text, SplitAt, Prefix = "file", Extension = "txt", InFile = 1)
SplitAt = Text, can be RegEx Prefix . Extension = filenameAUTOINCREMENT.Extension (Example: part_ . txt) InFile = 0 skip line e.g. do not include the actual line in any of the output files InFile = 1 include line IN current file InFile = 2 include line IN next file
Note: If you pass on a variable to TF_SplitFileByLines, the array size will be returned
as Prefix0 and the array elements as Prefix1, Prefix2 etc similar to the AHK StringSplit command.
The Extention parameter is ignored when using variables.
Some characters are illegal such as - + @ % & * _ \ / [ ] etc to use in Prefix, stick to a-z A-Z.
TF_SplitFileByText("File.txt", "button", "part", "zec", 1) ; split source file on every line with the word button, include that line INFILE ;illlustrate use of variables and returned arrays: TF_SplitFileByText(Variable, "keyboard", "part", "zec", 1) MsgBox % "Array size: " . Part0 . "`n1st array element: " Part1
TF_Merge(FileList, Separator = "`n", FileName = "merged.txt")
Example FileList:
FileList= ( file1.txt file2.txt file3.txt )
Note: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.
; using Loop (files & folders) to create one quickly if you want to merge all TXT files for example: Loop, c:\*.txt FileList .= A_LoopFileFullPath "`n" TF_Merge(FileList) ; will create merged.txt, you can use ! to overwrite an excisting file if you want
; using FileSelectFile to select files to merged: (Thanks for asking Vitor, http://www.autohotkey.com/forum/viewtopic.php?p=335329#335329) FileDelete merged.txt ; not required FileList= FileSelectFile, FileList, M 1,,, *.txt ; M allows you to select multiple files while holding down the left ctrl button If (ErrorLevel = 1) or (FileList = "") ExitApp ; no files selected Path:=TF_ReadLines(FileList,1,1,1) ; the first line holds the directory of the selected files, so read path FileList:=TF_RemoveLines(FileList,1,1) ; remove path from filelist FileList:=TF_InsertPrefix(FileList, "", "", Path . "\") ; make sure all files have full paths to file so the are read correctly TF_Merge(FileList) ; will create a file in the current script dir called merged.txt you can also specify another filename, take into account the filedelete merged.txt above ; You could skip the Path:= step above by calling TF_ReadLines directly in TF_InsertPrefix, but you would have to delete the first line AFTER it like so: ;FileList:=TF_InsertPrefix(FileList, "", "", TF_ReadLines(FileList,1,1,1) . "\") ;FileList:=TF_RemoveLines(FileList,1,1)
TF_Prepend(File1, File2)
Note: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.
TF_Append(File1, File2)
Note: TF_Merge, TF_Prepend, TF_Append currently do not support variables and only work with FILES.
TF_Wrap(Text, Columns = 80, AllowBreak = 0, StartLine = 1, EndLine = 0)
AllowBreak = 0 will not "break" words, so it will take into account whole words and not chop them off. AllowBreak = 1 will break words
TF_Wrap("File.txt",60) ; wrap at col 60
TF_WhiteSpace(Text, RemoveLeading = 1, RemoveTrailing = 1, StartLine = 1, EndLine = 0)
RemoveLeading = 0 Do not remove leading white space of lines RemoveLeading = 1 Remove leading white space of lines RemoveTrailing = 0 Do not remove trailing white space of lines RemoveTrailing = 1 Remove trailing white space of lines
TF_WhiteSpace("File.txt", 1, 0, "5-10") ; remove leading and keep trailing whitespace in lines 5 to 10
TF_Substract(File1, File2, PartialMatch = 0)
File2: you can use !file2 to overwrite file2 otherwise output is file2_copy.txt PartialMatch = 0 lines from file1 must appear as is, case insensitive PartialMatch = 1 allow for paRTIal match of line
TF_RangeReplace(Text, SearchTextBegin, SearchTextEnd, ReplaceText = "", CaseSensitive = "False", KeepBegin = 0, KeepEnd = 0)
Note: similar to "BK Replace EM" Range Replacement (highly recommend piece of software by the way, see link above). Basically an easier shortcut for a RegExp.
KeepBegin = 0 Remove SearchTextBegin from file KeepBegin = 1 Do not remove SearchTextBegin from file (saves you the trouble of putting it back in via ReplaceText) KeepEnd = 0 Remove SearchTextEnd from file KeepEnd = 1 Do not remove SearchTextEnd from file (saves you the trouble of putting it back in via ReplaceText) SearchTextBegin = "" e.g. empty means from START of File *1 SearchTextEnd = "" e.g. empty means until END of File *1
*1 if you pass on empty strings to SearchTextBegin and SearchTextEnd the entire
file will replaced with the replacement text.
SearchTextBegin/End can be on the same line. Remember this LIB mainly
operates on a line by line basis.
This Function only operates on the FIRST SearchTextBegin to the FIRST
SearchTextEnd it finds.
Range=[insert this`ntext for the`nrange replace Text`ntest function] TF_RangeReplace("File.txt", "Create hotkeys for keyboard", "into an EXE file", Range)
TF_MakeFile(Text, Lines = 1, Columns = 1, Fill = " ")
Sometimes you need an "empty" file before you can start adding line numbers or putting data into a file.
TF_Tab2Spaces(Text, TabStop = 4, StartLine = 1, EndLine = 0)
TabStop = number of spaces to replace a TAB with, so 4 means a TAB will be replaced by 4 spaces
TF_Spaces2Tab(Text, TabStop = 4, StartLine = 1, EndLine = 0)
TabStop = number of spaces to replace with a TAB, so 4 means 4 spaces will be replaced by a TAB
TF_Sort(Text, SortOptions = "", StartLine = 1, EndLine = 0)
SortOptions: use the SORT options http://www.autohotkey.com/docs/commands/Sort.htm
Note: StartLine can not have multiple sections, increments or multiple lines in this case. When dealing with variables/strings instead of text files the native AHK Sort command is of course more useful.
TF_Save(Text, FileName, OverWrite = 1)
OverWrite = 0 create filename_copy.ext if filename.ext exists OverWrite = 1 will overwrite filename.ext if filename.ext exists (default)
TF_FindLines(Text, SearchText = "", CaseSensitive = false, StartLine = 1, EndLine = 0)
Note: as of TF v3.1 TF_Find can replicate the results of TF_FindLines + additional features. This function is kept in for backwards compatibility. Only if you relied on CaseSensitive you should update your script as this is no longer a valid parameter. See the compatibility notes at TF_Find.
History v3.3, 16 April 2010
History v3.2, 20 February 2010
History v3.1, 09 December 2009
History v3.0, 27 November 2009
Complete overhaul of library, now accepts files & variables for input and output:
History v2.5 fix, 01 November 2009
Unreleased, but available on request :-)
Note that in 2.4a TF_MakeFile and TF_ConCat do not produce output files, easy to fix if you are
determined to use an older version of TF.
History v2.4a fix, 10 August 2009:
History v2.4 update, 06 August 2009:
History v2.3b update, 03 August 2009:
History v2.3a update/bugfix (29 July 2009, HugoV, ribbet.1, Murp|e)
Fixed/Changed:
History v2.3 (28 July 2009, HugoV)
* Note: yes they are a bit silly, but I find them to be useful as they serve as a shorthand for TF_ReplaceInLines. They are by no means "intelligent". Thanks to infogulch for the idea: http://www.autohotkey.com/forum/viewtopic.php?p=204570#204570
Also thanks to Murp|e for pointing out some errors in the documentation (TF_COL* functions).
History v2.2 (10 July 2009, HugoV)
History v2.1 (HugoV)
History v2.0 (Heresy, HugoV)
History prior 2.0 (Heresy, HugoV)