Page 1 of 1

Adding Lines Into File

PostPosted: Fri May 22, 2015 7:58 pm
by ajhunt
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.

Re: Adding Lines Into File

PostPosted: Sat May 23, 2015 7:30 am
by Gaev
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 ?

Re: Adding Lines Into File

PostPosted: Sat May 23, 2015 7:52 am
by ajhunt
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.

Re: Adding Lines Into File

PostPosted: Sat May 23, 2015 11:21 am
by Gaev
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" "" ""

Re: Adding Lines Into File

PostPosted: Sun May 24, 2015 10:31 am
by ajhunt
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.

Re: Adding Lines Into File

PostPosted: Sun May 24, 2015 4:48 pm
by Neosoft Support
Wow great job Gaev, perfectly does the job just right - your a superstar.


I agree. Gaev rocks!

Re: Adding Lines Into File

PostPosted: Tue May 26, 2015 3:33 am
by ajhunt
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

Re: Adding Lines Into File

PostPosted: Tue May 26, 2015 7:11 am
by Gaev
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.

Re: Adding Lines Into File

PostPosted: Tue May 26, 2015 8:21 am
by ajhunt
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