Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SDK LrFileUtils.readFile adds extra CR characters on Windows - is this normal?

Participant ,
Sep 14, 2025 Sep 14, 2025

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

LightroomStatistics_0-1757918839539.png

Lightroom logger file

LightroomStatistics_1-1757918925310.png

 

TOPICS
SDK , Windows
28
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation