Hello Community
I'm looking for a way to test if a file exists or not in the "LOCATION_COMMON_FILES"
Previously (version 9.x), it seems that the "getFile" function fire a try catch error in the file does not exists.
But it seems that it's not the case any more in 10.1.18 cloud edition
Any help ?
Thx in davance
Christian
Hello Christian,
Since getFile returns an array of bytes the most simple way is to check its lenght. If length equals 0, then file doesn't exist.
var testFile = Context.getFile("test.xml", Constants.LOCATION_COMMON_FILES) if (testFile.length>0) { ... }
---
BR, Nikita
Thank you both for your answer and your confirmation !!!
But I'm not sure this will be the answer in some cases. A zero length file can exists and may be lock by an other user than me....
Anyway, this is the Aris answer for the moment and for my purpose, i will first the "zero length" technic, but be carefull with the write rigth...
Meilleures salutations,
Christian
You can use the ScriptAdmin report component to explore the Common Files directory.
Example:
var nLocale = Context.getSelectedLanguage();
var scriptAdminComponent = Context.getComponent("ScriptAdmin");
function getCommmonCategoryComponentID() {
var allScriptComponentInfos = scriptAdminComponent.getScriptComponents();
for each(var scriptComponentInfo in allScriptComponentInfos) {
if(scriptComponentInfo.getComponentName() == "common") {
return scriptComponentInfo.getComponentID();
}
}
throw new Packages.java.lang.IllegalStateException("Common script category not found");
}
function getCommonFileNames() {
var commonScriptComponentID = getCommmonCategoryComponentID();
var allScriptInfos = scriptAdminComponent.getScriptInfos(commonScriptComponentID, null, nLocale);
function mapScriptInfoToName(someScriptInfo) {
return someScriptInfo.getName();
}
return allScriptInfos.map(mapScriptInfoToName).sort();
}
var result = getCommonFileNames();
This creates a result array of file names from the Common Files directory.
You can find out more about this by taking a look at "Methods for reports and semantic checks" > "Global Objects" > "Report component interfaces" > "ScriptAdmin" in the ARIS Script documentation.