Copy link to clipboard
Copied
Dear all,
A script to read an entry from an ini file fails although the file exists and can be opened with any editor - also the entry exists.
I have used this routine in other circumstances without this problem - coming back (after a detour to another script language) I do not understand...
Line 23 opens the file (or has it a problem?) - how to diagnose the problem?
The While is skipped and the error message is issued.
// FM-dict.jsx
#target framemaker
var appdata = app.UserSettingsDir; // %appdata%\Adobe\FrameMaker\<version>
var FMdictDir = appdata.replace (/Adobe.*/ , "D+DD\\FM-dict");
$.writeln (dddDir)
var iniFile = FMdictDir + "\\FM-dict.ini";
$.writeln (iniFile) // C:\Users\Klaus\AppData\Roaming\D+DD\FM-dict\FM-dict.inivar currentPrj = GetIniValue (iniFile, "currentPrj")
var currentDir = GetIniValue (iniFile, "currentDir")
$.writeln (currentPrj + " = " + currentDir)function GetIniValue (sIniFile, sValueName) { //===================================================
// Read an ini item into a variable
// Function returns sFoundValue
// sValueName is that used in the ini-file
var thisLine, match, notFound = true;
var regex = {
section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,
param: /^\s*([\w\.\-\_]+)\s*=\s*(.*?)\s*$/,
comment: /^\s*;.*$/ } ;
settingsFile = new File($.fileName.replace (/[^\\\/]+$/i , sIniFile)); // method Ric Quatro
settingsFile.open("r");while(!settingsFile.eof) {
thisLine = settingsFile.readln();
if (thisLine === null || thisLine === "") { // skip blank lines
continue;
}
if (regex.comment.test(thisLine)) { // skip comment lines
continue;
}
if (regex.section.test(thisLine)) { // ignore section lines
continue;
}match = thisLine.match(regex.param); // ignore undefined contents
if (match[1] == sValueName) {
sFoundValue = match[2];
notFound = false;
break; // found - leave loop
}
}
if (notFound) {
Alert ("Program error in GetIniValue: \n\nsValueName " + sValueName + "\nnot found in sIniFile " + sIniFile, Constants.FF_ALERT_CONTINUE_WARN);
stop;
}
settingsFile.close();
return sFoundValue;
} // --- end GetIniValue
With $.writeln (settingsFile.error) in line 24 I get "File or folder does not exist" - although It is exactly there and can be opened even by FrameMaker.
I have created a new file E:\FM-dict.ini - and replaced line 6 by
var iniFile = "E:\FM-dict.ini"
=> same error!
Message was edited by: Klaus Daube
I have now changed line 24 to
$.writeln (settingsFile.error + " =>" + settingsFile.name)
And what do I see? settingsFile.name is reported as E:FM-dict.ini => the backslash is missing and of course Windows does not find this file.
Hm, why could this routine work for some years correctly?
Well, in the string I must double the backslash:
var iniFile = "E:\\FM-dict.ini"
But this did not help either
I/O error =>FM-dict.ini
... need to break this down further
Ha, sometimes a pause solves such problems. After lunch before the coffe it came to my mind: It always worked for the ini file beeing in the same directory as the script...
Line 22 must read:
settingsFile = new File(sIniFile);
Thanks for listening!
Klaus
Copy link to clipboard
Copied
Where does this I/O error come from?
// RedIniFile.jsx
var iniFile = "E:\\Anything.ini"
$.writeln (iniFile) // E:\Anything.ini
var currentPrj = GetIniValue (iniFile, "currentPrj")function GetIniValue (sIniFile, sValueName) { //===================================================
settingsFile = new File($.fileName.replace (/[^\\\/]+$/i , sIniFile)); // method Ric Quatro
$.writeln (sIniFile + " => " + settingsFile.name) // E:\Anything.ini => Anything.ini
settingsFile.open("r");
$.writeln (settingsFile.error) // I/O error
settingsFile.close()
} // --- end GetIniValue
Anything.ini is in Windows code page 1252 as ini files must be
; Settings for the utility FM-dict.ahk
[FM-dict]
currentPrj =Client_B
currentDir =E:\Client_B\Dictionary
There was movie by Werner Herzog: Artisten in der Zirkuskuppel: ratlos
So do I
Copy link to clipboard
Copied
Ha, sometimes a pause solves such problems. After lunch before the coffe it came to my mind: It always worked for the ini file beeing in the same directory as the script...
Line 22 must read:
settingsFile = new File(sIniFile);
Thanks for listening!
Klaus