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.ini var 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