 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Sat Feb 20, 2010 2:15 pm Post subject: |
|
|
Interesting idea to check if a file is `r`n or `n delimited, I might borrow that
my version makes a comma separated list to build the new file
source: 1,2,3,4,5,6,7,8,9,10
output: 1,6,3,4,5,2,7,8,9,10
to swap lines 2 and 6
I can also swap sections, so 1,2,3 with 6,7,8:
out: 6,7,8,4,5,1,2,3,9,10
I think I will add a parameter to move lines, so one can move line 1 to 5 so something between a removeline and insertline (both are already in lib)
anyway, thanks for feedback _________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Sun Feb 21, 2010 12:21 pm Post subject: |
|
|
Ah there is something I want to hint. In my example I do this at end of function:
| Quote: | | Code: | | StringTrimRight, new, new, %nlen% |
|
It would be better to check if there is a newline at the end of original source, and only remove it if there is one. This keeps the last new line of original file and dont delete it.
This hint is in relation to my function.
And hey, I am building a standard library collection for redistributing. And TF is one of my favorites. One question remains: What is the license term? There is no explicit term given. I would like to know if I am allowed to redistribute this library with a collection of others. _________________ {1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <-- |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Mon Feb 22, 2010 7:54 am Post subject: |
|
|
Are you going to work with DerRaphael and his StdLib idea http://www.autohotkey.com/forum/viewtopic.php?t=54047 I like his ideas of downloading the libraries rather than a zipped package which will be outdated sooner or later (any further discussion there I suggest).
Don't know what license to use (can't be bothered to look into it, also I can't take credit for all functions as I borrowed parts here and there although most have been modified over time). _________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
vitor
Joined: 07 Feb 2010 Posts: 9 Location: Belgium
|
Posted: Wed Feb 24, 2010 7:23 pm Post subject: Text file select and replace HELP |
|
|
Need some help here,
Trying to do some operations in .txt files using this, but not working.
| Code: | #include C:\...\...\tf.ahk
FileSelectFile, selectfile, 1,,, *.txt
TF_TrimLeft(selectfile,"","",20)
TF_RemoveBlankLines(selectfile) |
Removing blanks is working, but trimming is not.
What am I doing wrong?
Thank you
__________________________________________________
TOSHIBA Portege M700, Intel Core2 DUO, T8100 @ 2.1GHz, 2,0GB RAM
MS Windows XP Tablet Edition SP3
EmergeDesktop, Samurize, StokeIt, DOpus, PDF Revu, AHK, MenuApp. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Wed Feb 24, 2010 9:11 pm Post subject: |
|
|
To write back the changes to the selected file: | Code: | #include C:\...\...\tf.ahk
FileSelectFile, selectfile, 1,,, *.txt
TF_TrimLeft("!" . selectfile,"","",20)
TF_RemoveBlankLines("!" . selectfile) |
or
To write back the changes to the selected file: | Code: | #include C:\...\...\tf.ahk
FileSelectFile, selectfile, 1,,, *.txt
TF_TrimLeft(selectfile,"","",20) ; this will create selectfile_copy so:
SplitPath, selectfile , , OutDir, OutExtension, OutNameNoExt
NewFile:="!" . OutDir . OutNameNoExt . "_copy." . OutExtension ; will retreive the selectfile_copy created by the TF_TrimLeft above so the TF below can use it.
TF_RemoveBlankLines(newfile) | read this http://www.autohotkey.com/forum/viewtopic.php?p=296951#296951 and the post(s) below or http://www.autohotkey.net/~hugov/tf-lib.htm#TextfileAndPrefix the example below "If you want to use multiple TF functions on a single file it is advised to use the ! Prefix" _________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
vitor
Joined: 07 Feb 2010 Posts: 9 Location: Belgium
|
Posted: Fri Feb 26, 2010 2:48 pm Post subject: |
|
|
Sorry for the late reply.
That worked great!
Well, since the master himself is helping us, would it be too much asking how to use TF_merge on the same scrip?
Something like, selecting "n" files, merging them into one, trimming & removing blank lines on the merged file.
Thank you in advance.
______________________________________________
TOSHIBA Portege M700, Intel Core2 DUO, T8100 @ 2.1GHz, 2,0GB RAM
MS Windows XP Tablet Edition SP3
EmergeDesktop, Samurize, StokeIt, DOpus, PDF Revu, AHK, MenuApp. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Fri Feb 26, 2010 3:54 pm Post subject: |
|
|
| Code: | FileDelete merged.txt
Loop, *.txt ; build filelist using loop
FileList .= A_LoopFileLongPath "`n" ; or build the filelist as shown in the example http://www.autohotkey.net/~hugov/tf-lib.htm#TF_Merge
TF_Merge(FileList) ; will create a file in the current script dir called merged.txt you can also specify another filename
TF_TrimLeft("!merged.txt","","",20)
TF_RemoveBlankLines("!merged.txt") |
Note: I was looking at the documentation and spotted an error as the Separator and FileName parameter where swapped in the description of the function, so in case you had any errors using it that was the problem. The doc has been fixed.
Note2: I tried with FileSelectFile with the multi-select option but for some peculiar reason it doesn't want to read and merge the specified files, I will try to investigate as to why over the weekend so there may be a TF_Merge fix if I can find out why. The above script works so does creating your own filelist variable as shown in the documentation. The fileselectfile just borks... _________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Fri Feb 26, 2010 4:15 pm Post subject: |
|
|
@vitor: Try this | Code: | FileDelete merged.txt
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 appears to hold the directory of the selected files read path
FileList:=TF_RemoveLines(FileList,1,1) ; remove path
FileList:=TF_InsertPrefix(FileList, "", "", Path . "\") ; make sure all files have full paths to file
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
TF_TrimLeft("!merged.txt","","",20) ; trimleft 20 chars
TF_RemoveBlankLines("!merged.txt") ; remove blanklines |
_________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
vitor
Joined: 07 Feb 2010 Posts: 9 Location: Belgium
|
Posted: Fri Feb 26, 2010 4:32 pm Post subject: |
|
|
You're the man
Worked like a charm.
Thank you.
___________________________________________________
TOSHIBA Portege M700, Intel Core2 DUO, T8100 @ 2.1GHz, 2,0GB RAM
MS Windows XP Tablet Edition SP3
EmergeDesktop, Samurize, StokeIt, DOpus, PDF Revu, AHK, MenuApp. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1237
|
Posted: Thu Mar 04, 2010 5:14 pm Post subject: |
|
|
Thanks hugov
The "wrap" function saved me lots of time. Your work is very much appreciated! |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
manek Guest
|
Posted: Sat Mar 06, 2010 1:47 pm Post subject: |
|
|
i was wondering if your TF_RemoveLines
could be used like this :
TF_RemoveLines("File.txt", someline, another line, line number 3)
so you specify the names of the lines you want to be removed and not their numbers |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Sat Mar 06, 2010 3:11 pm Post subject: |
|
|
| manek wrote: | | so you specify the names of the lines you want to be removed and not their numbers | I'm not sure what you mean by names of lines, perhaps the text of a line like so:
before:
this is test
with a number of lines
to show how you
can delete "names" from a
file or variable
--> Remove "to show how you"
after:
this is test
with a number of lines
can delete "names" from a
file or variable
If you could provide an example I might have an idea on how to help. _________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
manek Guest
|
Posted: Sat Mar 06, 2010 6:04 pm Post subject: |
|
|
| hugov wrote: | I'm not sure what you mean by names of lines, perhaps the text of a line like so:
before:
this is test
with a number of lines
to show how you
can delete "names" from a
file or variable
--> Remove "to show how you"
after:
this is test
with a number of lines
can delete "names" from a
file or variable
If you could provide an example I might have an idea on how to help. |
yeah something like that
so if i wanted to remove "to show you how" i would have to do this :
TF_RemoveLines("File.txt", to show you how)
if i wanted to remove the lines "this is test" and "file or variable" i would have to do this :
TF_RemoveLines("File.txt", this is test, file or variable)
because we cant always know what the line number we want to delete is
it would be nice to be able to delete them by name if you get what i mean |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|