Copy link to clipboard
Copied
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
Adjust File.encoding ...
Dirk
Copy link to clipboard
Copied
Loic,
You can use decodeURI (myFile.name) to replace special characters with basic ones.
Peter
Copy link to clipboard
Copied
Adjust File.encoding ...
Dirk
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Yeah thanks Dirk,
The File.encode(String) was a bit disturbing for me at first but it did the trick 😉
Regards,
Loic
Copy link to clipboard
Copied
I think Dirk meant:
txtFile.encoding = "UTF8";
Harbs
Copy link to clipboard
Copied
Hi Harbs,
Ok, I will have a look when I have my head out of water (ie job) 😄
A+ Loic
Find more inspiration, events, and resources on the new Adobe Community
Explore Now