Copy link to clipboard
Copied
While reading a log file from a Python program I noticed that LrFileUtils.readFile adds "CR" character for every new line "CRLF" in Windows.
In the sample script below I compare "LrFileUtils.readFile" with "io"
Is this normal or is this a bug?
File contents
line 1
line 2
line 3
To reproduce I use this small script
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrFileUtils = import "LrFileUtils"
local JSON = require "JSON"
local inspect = require "inspect"
local logFilename = 'TestReadFile'
local myLogger = import 'LrLogger' (logFilename)
myLogger:enable("logfile")
local filePath = "D:/Temp/file.txt"
local function readJsonFile(path)
local content
local file = io.open(path, "r")
if file then
content = file:read("*all")
file:close()
else
myLogger:info("Error opening file.")
end
return content
end
local function writeFile(content)
local file = io.open(filePath, "w")
if file then
file:write(content)
file:close()
myLogger:info("String written to file successfully.")
else
myLogger:info("Error opening file.")
end
end
local function main(context)
local text = "line 1\nline 2\nline 3\n"
writeFile(text)
-- Open file file LrFileUtils.readFile( path )
local contents = LrFileUtils.readFile(filePath)
myLogger:info("File contents from LrFileUtils.readFile", contents)
contents = readJsonFile(filePath)
myLogger:info("File contents from io", contents)
end
LrFunctionContext.postAsyncTaskWithContext("Start culling", function(context)
LrDialogs.attachErrorDialogToFunctionContext(context)
main(context)
end)
In Windows using Notepad++ this is how the file look like:
File.txt
Lightroom logger file
Have something to add?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now