Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
General Discussion
 RoboTask Forum : General Discussion
Subject Topic: Helping with loop please! Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
bama
Newbie
Newbie


Joined: 25 June 2010
Location: Canada
Online Status: Offline
Posts: 2
Posted: 25 June 2010 at 11:21am | IP Logged Quote bama

I wonder if somebody can help with this.
I have 2 folders, the first one has many text files (hundreds), each text file contain one article, the article starts with a title, an empty line, then the first paragraph.
The second folder has one text file, in that file there are sentences (hundreds), each sentence is in a separate line.
What I need to do is to insert one of the sentences from the file that contain them into each article(after the first paragraph) in each file(in the folder that contains the article files.
I recorded the action, and it work fine for the first text, what should I do to make it go automatically from the first text, to do the next and so on to do all of them, I understand that I need a loop but I don't know how to do it, please help!

Back to Top View bama's Profile Search for other posts by bama
 
igimax
Newbie
Newbie
Avatar

Joined: 07 July 2010
Location: Iran
Online Status: Offline
Posts: 7
Posted: 08 July 2010 at 5:21am | IP Logged Quote igimax

Hi bama

. Well I have 2 question! base on your needs:
Quote:
What I need to do is to insert one of the sentences from the file that contain them into each article(after the first paragraph)"

. two thing you forgot to mention here:
1) What is it between "first paragraph" and "second paragraph"?
2) Adding those lines from second file into those articles, are first line at second file go to first article was found! and second line from second file go to second file article was found and ....?

. If your answer for first question is "empty line" and all article files like each other in this matter, and If your second answer is yes, then you can simply use three nested loops. (File Loop\Text Loop\Text Loop) if your answer like those and need more help about these loops let me know.

.  But if your answers are different than above answers, Please explain them!! (it will be more helpful, if you can upload at least three of those articles somewhere! and give us a link for download them)

Good Luck
IgImAx



__________________
Teach others to Learn more yourself
Back to Top View igimax's Profile Search for other posts by igimax Visit igimax's Homepage
 
bama
Newbie
Newbie


Joined: 25 June 2010
Location: Canada
Online Status: Offline
Posts: 2
Posted: 09 July 2010 at 1:34am | IP Logged Quote bama

Thank You igimax for trying to help.

It's how you understood it.
So, I want to insert a sentence from the text file (in the second folder), into one of the text files (the articles in the first folder), and repeat that for all of them. The insertion should be at first line of the text file then I should have an empty line, or (the other option: after the first paragraph (after the first paragraph there is the second paragraph but I don't have an empty line in between)
I don't understand how to do
(File Loop\Text Loop\Text Loop), can you explain in more details how to do it? Thanks.
Back to Top View bama's Profile Search for other posts by bama
 
igimax
Newbie
Newbie
Avatar

Joined: 07 July 2010
Location: Iran
Online Status: Offline
Posts: 7
Posted: 09 July 2010 at 7:25am | IP Logged Quote igimax

Hi bama

Quote:
Thank You igimax for trying to help.

. No problem! I will be happy to help others, If I can!

[Quote]The insertion should be at first line of the text file then I should have an empty line, or (the other option: after the first paragraph (after the first paragraph there is the second paragraph but I don't have an empty line in between)[/Quote]
. The new option need less coding! But I found I was mistaken about one of the RT commands! So! now you can do both options with RT.

. Todo both above options you still need those three loops, But the "Insertion Point" place inside second loop and base on which option you choose, writing the codes for each one will be different! (of course!)

. The code will do this in simple steps:
1) found "Article Files" at first folder by *.txt condition.
2) Read lines of founded "Article File"
3) Write each lines at new file at another location with the same filename of "Article File"
4) When it's reach to "Insertion Point", the sentence line will write at new file.
5) After writing all lines go to step 1 to found another "Article File"

. Your loops should look like this simple codes:

(Read/Bold worlds are RT Commands and variable are GREEN/Bold):
//---------------------------------------------------------- ------
01> File Loop (return "full path & file name" of all files at "Article Folder" that have "*.txt" condition, one by one and store it at a variable. let's call it "ARTICLE_FILENAME")

02>>... COUNT_FOUNDED_ARTICLE_FILES += 1 (Add one to this variable, we will use this counter to know which line of "second text files" should be insert to the current "Article file")

03>>... NEW_ARTICLE_FILENAME (store new path + same article filename at this variable)

04>> Text Loop (read line by line of "ARTICLE_FILENAME" file and store each line at "READ_ARTICLE_LINE")

05>>>...Check If "Insertion Point" reach codes?? (base on your choose insertion point will be place here, and if it reach, variable "INSERTION_STATUS" will be True)

06>>>... If {INSERTION_STATUS}==True

07>>>>... Text Loop (Read Line by line from "Sentence text file" and store it at "READ_SENTENCE_LINE")

08>>>>... COUNT_READ_LINES += 1 (Count Read lines from "Sentence text file")

09>>>>... IF {COUNT_READ_LINES} == {COUNT_FOUNDED_ARTICLE_FILES}

10>>>>>... Write Text File {READ_SENTENCE_LINE} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)

11>>>>>... Write Text File {READ_ARTICLE_LINE} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)

12>>>>>... Break

13>>><... END IF

14>>><... End Loop

15>>> ELSE (INSERTION_STATUS==False)

16>>>>... Write Text File {READ_ARTICLE_LINE} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)

17>><... End IF

18>< END LOOP (Read from Article File)

19< End Loop (Found "Article Files")
//---------------------------------------------------------- ------

. you can choose any variable name you like! also at above lines, I write simple algorithm to show you how you can use those loops and I did not write a full code for you! (for instance, some variables should set to 0 or false before/after some conditions or maybe you should add some extra conditions...)

. But about "Insertion point":

First Option (Insert sentence at the beginning of article)
----------------------------------------------------------
.  you can use a Boolean variable to do this. Just create it (for example FIRST_LINE) before "
04" line with "True" value.
. at "05>>>" line place an "IF" section by this condition:

> IF {First_Line}== True

>> FIRST_LINE= False

>>
INSERTION_STATUS= True

> End IF


Second Option (Insert sentence before 4th line)
--------------------------------------------------
.  At text files each line will end with "carriage return (CR)"  (Enter Key). "Text Loop"
command at RT, read a line that ended with CR. Each paragraph end with CR, so in fact each paragraph with too many lines can be only one line! To found that, at windows OS, you can open text files with Notepad and then turn of "Word Warp" option from "Format" menu of Notepad.

. Ok! base on your infoz! each Article files start with a title line then an empty line and then first paragraph. some thing like this:
//----------------------
Article Title<CR>
<CR>
First Paragraph<CR>
Second Paragraph<CR>
....
//----------------------

. therefor, base on above sample, If we read 4 lines at "04>> Text Loop" line, we will reach to Insertion point! to do that, you will need to create a numerical variable (a Counter) before line "04>> Text Loop" with 0 value. ( INSERTION_POINT_COUNTER)

. at "05>>>" line place these codes:

> INSERTION_POINT_COUNTER += 1

> IF {INSERTION_POINT_COUNTER} == 4

>> INSERTION_STATUS= True

> End IF



. Ok, that's should be all you need!?

Good Luck
IgImAx


Edited by igimax on 09 July 2010 at 8:13am


__________________
Teach others to Learn more yourself
Back to Top View igimax's Profile Search for other posts by igimax Visit igimax's Homepage
 
igimax
Newbie
Newbie
Avatar

Joined: 07 July 2010
Location: Iran
Online Status: Offline
Posts: 7
Posted: 09 July 2010 at 10:37am | IP Logged Quote igimax

Hi bama

. I'm new at RT world! I knew about array variables at RT but I was mistaken about How I can use them! now, I did some test on array variables and I found the better and faster way to execute above code!

(Read/Bold worlds are RT Commands and variable are GREEN/Bold):
//-------------------------------------------------------- -- ------
01> Create Variable ALL_SENTENCES = ""

02> Text Loop (Read Line by line from "Sentence text file" and store it at "READ_SENTENCE_LINE")

03>> IF ALL_SENTENCES == Is Empty String

04>>> Set Variable ALL_SENTENCES = "{READ_SENTENCE_LINE}" (Expand Value = True)

05>> ELSE

06>>> Set Variable ALL_SENTENCES = {ALL_SENTENCES},"{READ_SENTENCE_LINE}" (Expand Value = True)

07>> End IF

08> End Loop

09>> Set Variable COUNT_FOUNDED_ARTICLE_FILES = 0

10> File Loop (x:\Article Path\*.txt  put file "Path+Filename" into "ARTICLE_FILENAME")

11>> Set Variable NEW_ARTICLE_FILENAME (y:\temp\current article filename.txt)

12>> Text Loop (read line by line of "ARTICLE_FILENAME" file and store each line at "READ_ARTICLE_LINE")

13>>> Check If "Insertion Point" reach codes?? (base on your choose insertion point will be place here, and if it reach, variable "INSERTION_STATUS" will be True)

14>>> If {INSERTION_STATUS}==True

15>>>> Write Text File {ALL_SENTENCES({COUNT_FOUNDED_ARTICLE_FILES})} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)

16>>>> Write Text File {READ_ARTICLE_LINE} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)

17>>> ELSE (INSERTION_STATUS==False)

18>>>> Write Text File {READ_ARTICLE_LINE} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)

19>>> End IF

20>> END LOOP (Read from "Article File")

21>> Set Variable COUNT_FOUNDED_ARTICLE_FILES += 1

22> End Loop (Found another "Article File")
//-------------------------------------------------------- -- ------

.
This new way will be so much faster and have better algorithm! Insertion Point check codes, will be the same as before!

. Do not forget to put those "" at lines 04 and 06 around the variable.

Good Luck
IgImAx



__________________
Teach others to Learn more yourself
Back to Top View igimax's Profile Search for other posts by igimax Visit igimax's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.0781 seconds.