Skip to main content
rombanks
Inspiring
March 28, 2015
Answered

framescript: write to text file

  • March 28, 2015
  • 1 reply
  • 807 views

Hello fellows,

When I loop through a list of book files and write their names to the FM console, the full list is displayed. However, when I write the list to a text file, only the 1st file name is written. Any ideas why?

Loop ForEach(BookComponent) In(vCurrentBook) LoopVar(v_File)

...

Write Console v_File;

vs.:

Set vPath = v_UserPath+DIRSEP+'_'+'Test'+'.txt';

New TextFile File(vPath) NewVar(vFile_Listing);

Write Object(vFile_Listing) v_File;

EndLoop

Thank you for your input in advance!

Roman

This topic has been closed for replies.
Correct answer frameexpert

Hi Roman, This works for me:

Set sPath = 'C:\DATA\Test.txt';

New TextFile File(sPath) NewVar(oFile);

Set oBook = ActiveBook;

Loop ForEach(BookComponent) In(oBook) LoopVar(oBookComp)

  Write Object(oFile) oBookComp.Name;

EndLoop

Close TextFile Object(oFile);

You have to close the text file when you are done with it. Maybe that is the problem with your code.

-Rick

1 reply

rombanks
rombanksAuthor
Inspiring
March 31, 2015

Fellows,

Do you have any ideas?

I tried to add "+ CHARCR" to make the next book component to appear on the next line, but that did not help.

Thanks for your input in advance!

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
March 31, 2015

Hi Roman, This works for me:

Set sPath = 'C:\DATA\Test.txt';

New TextFile File(sPath) NewVar(oFile);

Set oBook = ActiveBook;

Loop ForEach(BookComponent) In(oBook) LoopVar(oBookComp)

  Write Object(oFile) oBookComp.Name;

EndLoop

Close TextFile Object(oFile);

You have to close the text file when you are done with it. Maybe that is the problem with your code.

-Rick

www.frameexpert.com
rombanks
rombanksAuthor
Inspiring
March 31, 2015

Hi Rick,

Thank you for your response and for the suggestion!

I found the problem -- I put the file creation function inside the loop...

Your example helped me understand what the problem is.

By the way, I do not add any instruction to open the created text file, so why do I need to close it?

Thank you again!

Best regards,

Roman