Reading a file line by line

Home Forums General Programming Reading a file line by line

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #66973
    goodweather
    Participant
      • Topics: 45
      • Replies: 550
      • Total: 595
      • ★★★

      Hi,
      I’d like to read from and write to a text file (.txt) line by line.
      Tried this but without any success. Any hint? I must be close…

      fileToRead = utils.openFileWindow(
      	"Open file to read as text",
      	File.getSpecialLocation(File.userHomeDirectory),
      	"*.*",
      	true
      )
      
      if fileToRead:existsAsFile() then
      	while true do
              line = fileToRead:read()
              if line == nil then break end
              	print (line)
      	end
      end

      Getting Error message: [string “openFile”]:26: attempt to call method ‘read’ (a nil value)

      Thx and Merry Xmas to all!

      #70109
      artofnois
      Participant
        • Topics: 26
        • Replies: 40
        • Total: 66

        I need this too. Any idea?
        Is for save an reload config files like:

        PATH=/home/patches\n
        VAR1=Lead.syx\n
        VAR2=Pad01.syx\n
        EOF

        And how to split a line by the caracter ‘=’

      Viewing 2 posts - 1 through 2 (of 2 total)
      • The forum ‘Programming’ is closed to new topics and replies.
      There is currently 0 users and 72 guests online
      No users are currently active
      Forum Statistics
      Threads: 2,495, Posts: 17,374, Members: 77,605
      Most users ever online was 12 on January 22, 2019 3:47 pm
      Ctrlr