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

[JS MAC] File path problem with special characters

People's Champ ,
Feb 09, 2010 Feb 09, 2010

Hello,

I am trying to report a file 's path on a text file. One of the folders includes a special character such as "Loïc".

So when I try to write a txt file with that path, it fails.

Here is a snippet I have isolated for debugging.

The problem appears on a Mac but may be present on a PC as well.

//Considering an open file in Indesign

//This file is placed within a subfolder named "Loïc"

var theFile= File(app.activeDocument.fullName);
var myFileFullName = theFile.fsName;
var modifsArr = [];
modifsArr.push(myFileFullName);
var txtFile=File(Folder.desktop + "/test.txt");
if(File(Folder.desktop + "/test.txt").exists ==false)
{
    var txtFile=new File(Folder.desktop + "/test.txt");
}

txtFile.open("e");
txtFile.seek(0,2);
modifsArr = modifsArr.join("\r");
theFile.write(modifsArr); //Here the writing fails
theFile.close();

How can I solve that ?

TIA

Loic

TOPICS
Scripting
1.4K
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

correct answers 1 Correct answer

Mentor , Feb 09, 2010 Feb 09, 2010

Adjust File.encoding ...

Dirk

Translate
Community Expert ,
Feb 09, 2010 Feb 09, 2010

Loic,

You can use decodeURI (myFile.name) to replace special characters with basic ones.

Peter

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
Mentor ,
Feb 09, 2010 Feb 09, 2010

Adjust File.encoding ...

Dirk

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
People's Champ ,
Feb 10, 2010 Feb 10, 2010

Hi Peter, Dirk,

Thanks a lot for your both answers,

Peter,

decodeURI(...) is what I tried in a first place but it didn't solve my matter.

Dirk,

I am trying your encoding suggestion asap.

Thanks once again to both of you.

Regards,

Loic

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
Community Expert ,
Feb 10, 2010 Feb 10, 2010

Dirk is correct, of course. As the problem occurs when writing some contents to the file, its encoding is what matters, not its name's encoding.

Peter

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
People's Champ ,
Feb 10, 2010 Feb 10, 2010

Yeah thanks Dirk,

The File.encode(String) was a bit disturbing for me at first but it did the trick 😉


Regards,

Loic

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
LEGEND ,
Feb 11, 2010 Feb 11, 2010

I think Dirk meant:

txtFile.encoding = "UTF8";

Harbs

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
People's Champ ,
Feb 11, 2010 Feb 11, 2010
LATEST

Hi Harbs,

Ok, I will have a look when I have my head out of water (ie job) 😄

A+ Loic

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