1 Reply Latest reply on Apr 3, 2009 4:39 AM by (Herb_Albert)

    Opening a Text File?

      I am having no luck opening a text file that contains comma delimited data. I have tried some different ways and am having no luck at all. I can't even get a open file dialog to appear when I click a button.

      I did not see any example of this in the sdk sample plugins.

      Anyone able to help me out.

      The file I am trying to load is "D:\Test\TestFile.txt".
        • 1. Re: Opening a Text File?
          Level 1
          If you did not escape the path's backslashes that may be part of the problem.

          Some example code:

          local LrDialogs = import 'LrDialogs'
          
          local LrFileUtils = import 'LrFileUtils'
          local LrPathUtils = import 'LrPathUtils'

          local file = 'C:\\temp\\Testfile1.txt'

          if not LrFileUtils.isReadable(file) then
          local dialogresult = LrDialogs.runOpenPanel {
            title = 'Select input text file',
            allowsMultipleSelection = false,
            initialDirectory = LrPathUtils.parent(file)
          }
          file = dialogresult and dialogresult[1] or nil
          end

          if file and LrFileUtils.isReadable(file) then
          local collectedLines = {}
          for line in io.lines(file) do table.insert(collectedLines, line) end
          LrDialogs.message(table.concat(collectedLines, '\n'))
          end


          Herb