AutoHotkey Community

It is currently May 27th, 2012, 4:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 194 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9, 10, 11 ... 13  Next
Author Message
 Post subject:
PostPosted: February 20th, 2010, 3:15 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 1:21 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
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. :D 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! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2010, 8:54 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 24th, 2010, 8:23 pm 
Offline

Joined: February 7th, 2010, 2:48 pm
Posts: 9
Location: Belgium
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 10:11 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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/viewtop ... 951#296951 and the post(s) below or http://www.autohotkey.net/~hugov/tf-lib ... eAndPrefix the example below "If you want to use multiple TF functions on a single file it is advised to use the ! Prefix"

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 3:48 pm 
Offline

Joined: February 7th, 2010, 2:48 pm
Posts: 9
Location: Belgium
Sorry for the late reply.:oops:

That worked great! :D

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 4:54 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 5:15 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
@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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 5:32 pm 
Offline

Joined: February 7th, 2010, 2:48 pm
Posts: 9
Location: Belgium
You're the man :wink:

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 5:33 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Good to hear. I had never worked with fileselectfile so I've learned something new 8)

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 6:14 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Thanks hugov :D

The "wrap" function saved me lots of time. Your work is very much appreciated!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 6:28 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Thanks - let me know if you have any suggestions for new functions or improvements.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 2:47 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 4:11 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 7:04 pm 
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


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 194 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9, 10, 11 ... 13  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 8 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