Skip to main content
Participant
April 2, 2009
Question

Opening a Text File?

  • April 2, 2009
  • 1 reply
  • 821 views
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".
This topic has been closed for replies.

1 reply

Known Participant
April 3, 2009
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