Question
Pegasystems Inc.
JP
Last activity: 25 Jun 2019 2:40 EDT
How to get the absolute path to the root directory of pega temp dir
Is there any Engine API which returns the FULL path to the root directory of Pega temp dir?
FULL path means "file://web:" or "file://default:" is replaced with the absolute path.
***Edited by Moderator: Pallavi to update platform capability tags***
-
Likes (1)
Sabry Ashroff -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
US
Hello,
You can try the below code to get the absolute path of the Pega temp directory,
tools.getSystemSettings().getFSSetting("initialization/explicittempdir", "" , true, false);
Hope it might help you.
Regards,
Mahesh M
Pegasystems Inc.
US
What's the use case? It's set at the application server level, so it's location should be known to the application server admins.
Pegasystems Inc.
JP
In my use case, I have to return the absolute csv file path to a 3rd party java api.
Accepted Solution
Pegasystems Inc.
US
Hello,
You can try the below code to get the absolute path of the Pega temp directory,
tools.getSystemSettings().getFSSetting("initialization/explicittempdir", "" , true, false);
Hope it might help you.
Regards,
Mahesh M
-
Sabry Ashroff Mahesh Komuravelli
NA
SG
Hi Mahesh,
I have tried the above in java code but i am getting blank value. Can you please explain how you used in your code.
Pegasystems Inc.
JP
//char sep = PRFile.separatorChar;
//absolute path to pega temp dir
String pegaTempDir= tools.getSystemSettings().getFSSetting("initialization/explicittempdir", "" , true, false);
//this path starts with "file://web:"
String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
//create svf directory where we creates csv file
String svfDirPath = pegaTempDir+exportPath.replaceAll("file://web:","")+"svf";
svfDirPath = svfDirPath.replaceAll("\\\\","/");
//oLog.error("svfDir===="+svfDir);
java.io.File svfDir = new java.io.File(svfDirPath);
if(svfDir.exists()==false){
try{
svfDir.mkdirs();
}catch(Exception ex){
throw ex;
}
}
DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils();
String fileNameParam = tools.getParamValue("FileName");
if(fileNameParam.equals("")){
fileNameParam = "RecordsToCSV";
}
Boolean appendTimeStamp = tools.getParamAsBoolean(ImmutablePropertyInfo.TYPE_TRUEFALSE,"AppendTimeStampToFileName");
FileName+=fileNameParam;
if(appendTimeStamp){
FileName+="_";
FileName+=dtu.getCurrentTimeStamp();
}
FileName+=".csv";
String CSVFilePath = exportPath+"/svf/"+FileName;
PRFile f = new PRFile(CSVFilePath);
try{
// Create file
PROutputStream stream = new PROutputStream(f);
PRWriter out = new PRWriter(stream, null, false);
// Bug with Excel reading a file starting with 'ID' as SYLK
//char sep = PRFile.separatorChar;
//absolute path to pega temp dir
String pegaTempDir= tools.getSystemSettings().getFSSetting("initialization/explicittempdir", "" , true, false);
//this path starts with "file://web:"
String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
//create svf directory where we creates csv file
String svfDirPath = pegaTempDir+exportPath.replaceAll("file://web:","")+"svf";
svfDirPath = svfDirPath.replaceAll("\\\\","/");
//oLog.error("svfDir===="+svfDir);
java.io.File svfDir = new java.io.File(svfDirPath);
if(svfDir.exists()==false){
try{
svfDir.mkdirs();
}catch(Exception ex){
throw ex;
}
}
DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils();
String fileNameParam = tools.getParamValue("FileName");
if(fileNameParam.equals("")){
fileNameParam = "RecordsToCSV";
}
Boolean appendTimeStamp = tools.getParamAsBoolean(ImmutablePropertyInfo.TYPE_TRUEFALSE,"AppendTimeStampToFileName");
FileName+=fileNameParam;
if(appendTimeStamp){
FileName+="_";
FileName+=dtu.getCurrentTimeStamp();
}
FileName+=".csv";
String CSVFilePath = exportPath+"/svf/"+FileName;
PRFile f = new PRFile(CSVFilePath);
try{
// Create file
PROutputStream stream = new PROutputStream(f);
PRWriter out = new PRWriter(stream, null, false);
// Bug with Excel reading a file starting with 'ID' as SYLK file. If CSV starts with ID, prepend an empty space.
if(CSVString.startsWith("ID")){
CSVString=" "+CSVString;
}
out.write(CSVString);
//Close the output stream
out.close();
// CSVFilePath is a relative path starts with file://web:, however we must return absolute path to the csv file.
tools.putParamValue("CSVFilePath",svfDirPath+"/"+FileName);
//oLog.error("CSVFilePath===="+svfDirPath+"/"+FileName);
}catch (Exception e) {
oLog.error("Error writing csv file: " + e.getMessage());
}