Highlighted

ExtendScript - Writing LF file on Windows

Community Beginner ,
Aug 19, 2020

Copy link to clipboard

Copied

Hi, 

 

I'm trying to use ExtendScript ot write a file to an LF (not CRLF) file in Windows. I'm finding that even when I write a string with \n characters, they are being replaced by \r\n characters in the final file.

 

Is there some magic I'm missing

 

 

 

var writeToFile = function (str, filePath) {
    var outFile = new File(filePath);
    if (outFile) { 
        outFile.encoding = "UTF-8";
        outFile.open("w", "TEXT", "????");
        outFile.write(str);
        outFile.close();
    }
}
 
for(var i=0;i<allMarkers.length;i++){
        var marker = allMarkers[i];
        var line = "AUTHOR\t" + marker.tc + "\tV1\tred\t\t1";
        str += line;
        if (i < allMarkers.length - 1){
            str += "\n"; //Aleays seems to be replaced by \r\n when writing the file
        }
    }
    var outputFilePath = "PATHTO\\" + sequenceName + ".txt";
    writeToFile(str, outputFilePath);

 

Adobe Community Professional
Correct answer by Tomas_Sinkunas | Adobe Community Professional

What if you specified line feed manually?

outFile.lineFeed = "Unix"; // "Windows", "Macintosh", "Unix"

 

More info here: http://estk.aenhancers.com/file-system-access/file-object.html?#file-object-properties

Topics

SDK

Views

19

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

ExtendScript - Writing LF file on Windows

Community Beginner ,
Aug 19, 2020

Copy link to clipboard

Copied

Hi, 

 

I'm trying to use ExtendScript ot write a file to an LF (not CRLF) file in Windows. I'm finding that even when I write a string with \n characters, they are being replaced by \r\n characters in the final file.

 

Is there some magic I'm missing

 

 

 

var writeToFile = function (str, filePath) {
    var outFile = new File(filePath);
    if (outFile) { 
        outFile.encoding = "UTF-8";
        outFile.open("w", "TEXT", "????");
        outFile.write(str);
        outFile.close();
    }
}
 
for(var i=0;i<allMarkers.length;i++){
        var marker = allMarkers[i];
        var line = "AUTHOR\t" + marker.tc + "\tV1\tred\t\t1";
        str += line;
        if (i < allMarkers.length - 1){
            str += "\n"; //Aleays seems to be replaced by \r\n when writing the file
        }
    }
    var outputFilePath = "PATHTO\\" + sequenceName + ".txt";
    writeToFile(str, outputFilePath);

 

Adobe Community Professional
Correct answer by Tomas_Sinkunas | Adobe Community Professional

What if you specified line feed manually?

outFile.lineFeed = "Unix"; // "Windows", "Macintosh", "Unix"

 

More info here: http://estk.aenhancers.com/file-system-access/file-object.html?#file-object-properties

Topics

SDK

Views

20

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

What if you specified line feed manually?

outFile.lineFeed = "Unix"; // "Windows", "Macintosh", "Unix"

 

More info here: http://estk.aenhancers.com/file-system-access/file-object.html?#file-object-properties

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
woodced LATEST
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

Excellent Tomas. That's works perfectly.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...