Source language: Translate to:

Adding Lines Into File

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Adding Lines Into File

Postby ajhunt » Fri May 22, 2015 7:58 pm

Can anyone please help. I have two text files containing lines of text, (PhotoList.txt - containing photo filenames of .jpg's) and (AdvertList.txt - containing advert filenames of .jpg's). I need to create a third file (PlayList.txt) with both together but with advert.jpg's filenames between photos.jpg's filenames. Example, if I set a variable say AdvertEvery=2, then write the first and second lines of PhotoList.txt, the first line of AdvertList.txt, third and forth lines of PhotoList.txt, second line of AdvertList.txt, etc etc - advert name being written every 2nd photo name. I keep trying loops and counters but just can't seem to figure it out. The PhotoList.txt could have say 50 filenames and the AdvertList.txt have 10 filenames (both may vary) so wanting a PlayList.txt with advertnames every 'x' between photonames. Hope that makes sense as late here and getting nowhere and no confused with it myself lol. Thanks for any help anyone can offer.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Adding Lines Into File

Postby Gaev » Sat May 23, 2015 7:30 am

ajhunt:

The PhotoList.txt could have say 50 filenames and the AdvertList.txt have 10 filenames (both may vary) so wanting a PlayList.txt with advertnames every 'x' between photonames.

What happens if, in your example above ...

a) x = 4 or less ? ... do you repeat the filenames from AdvertList.txt after the tenth line from PhotoList.txt ?

b) x = 6 or larger ? ... some of the lines in AdvertList.txt will not be used ?
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Adding Lines Into File

Postby ajhunt » Sat May 23, 2015 7:52 am

H Gaev,Yes want to repeat the Advert names from the start again until the Photo names run out. Thankyou for your time and help Gaev. Regards.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Adding Lines Into File

Postby Gaev » Sat May 23, 2015 11:21 am

ajhunt:

Code: Select all
... setup
SetVar "[PhotoListFile]" "![PubDir]PhotoList.txt"

SetVar "[AdvertListFile]" "![PubDir]AdvertList.txt"

SetVar "[PlayListFile]" "![PubDir]PlayList.txt"
FileErase "![PlayListFile]"

SetVar "[AdvertEvery]" "3"

FileLen "![PhotoListFile]" "[MaxPhotoLines]"
FileLen "![AdvertListFile]" "[MaxAdvertLines]"

... do it
SetVar "[NextAdvertLine]" "1"
SetVar "[PhotoCount]" "[AdvertEvery]"
Loop "1" "[MaxPhotoLines]" "[NextPhotoLine]"
   If "[PhotoCount]" "=" "0"
    ... insert Advert line
    FileRead "![AdvertListFile]" "[NextAdvertLine]" "[thisAdvertLine]"
    ... update next advert line
    SetVar "[NextAdvertLine]" "1+[NextAdvertLine]"
    If "[NextAdvertLine]" ">" "[MaxAdvertLines]"
        SetVar "[NextAdvertLine]" "1"
    EndIf
    ... write to PlayList
    FileWrite "![PlayListFile]" "Append" "[thisAdvertLine]"
    ... reset frequency counter
    Setvar "[PhotoCount]" "[AdvertEvery]"
   EndIf
   ... insert Photo line
    FileRead "[PhotoListFile]" "[NextPhotoLine]" "[thisPhotoLine]"
    FileWrite "![PlayListFile]" "Append" "[thisPhotoLine]"
   ... update frequency counter
   SetVar "[PhotoCount]" "[PhotoCount]-1"
EndLoop

Run "![PlayListFile]" "" "Normal" "" ""
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Adding Lines Into File

Postby ajhunt » Sun May 24, 2015 10:31 am

Wow great job Gaev, perfectly does the job just right - your a superstar. Thankyou so so much for your help as I Just could not get my head around it. Thankyou again Gaev.
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Adding Lines Into File

Postby Neosoft Support » Sun May 24, 2015 4:48 pm

Wow great job Gaev, perfectly does the job just right - your a superstar.


I agree. Gaev rocks!
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Adding Lines Into File

Postby ajhunt » Tue May 26, 2015 3:33 am

Hi again superstar Geav. Adding in the lines is working like a dream. I have another to ask if you don't mind. I have all the lines in the PlayList.txt but sometimes I would like to have all the lines in Random order - what would be my best way of trying this - a loop and somehow not have the same line used twice. Can you please point me in the right direction. Thanks again Geav. Basicall a routine to random any .txt file into another temp.txt file
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom

Re: Adding Lines Into File

Postby Gaev » Tue May 26, 2015 7:11 am

ajhunt:

Basicall a routine to random any .txt file into another temp.txt file

See if you can adapt the code here to create the (randomized list) file you want ... it tells you how you can use "lines in a text file" instead of a "comma seaparated list" as input ... the random item it returns with each iteration can be written to the temporary (randomized list) file that you can then feed into the previous functionality for injecting advert lines.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Adding Lines Into File

Postby ajhunt » Tue May 26, 2015 8:21 am

Thats great Geav, thankyou so much - I'll be able to crib from that code. Thankyou again for your terrific help Geav. Best regards Anthony
ajhunt
 
Posts: 215
Joined: Sat Apr 23, 2005 2:33 pm
Location: United Kingdom


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron