Question
Rabobank
SE
Last activity: 12 Oct 2017 12:45 EDT
How to know if a file exists ?
Hi All,
Is there any way where i can get know whether a particular file is available in "serviceExport" folder?
If so how to check it.
Eg: " file://web:/StaticContent/global/ServiceExport/ABC.xlsx
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Rabobank
SE
Thanks for your reply. I used JAVA step to check if a particular file exists,
PRFile folder = new PRFile("file://web:/StaticContent/global/ServiceExport/");
PRFile[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].toString().equals("file://web:/StaticContent/global/ServiceExport/AgeOfLoanReport.csv")){
APPName = "true";
}
Based on the APPName i am continuing my activity.
Pegasystems Inc.
AU
Hi Sarath,
You can use a java step in activity to check if the file exists or not. If you are looking for a way to get the directory path to a variable , you can use it as
String filePath = pega.getStaticContentUtils().getServiceExportRoot();
Thanks,
Karthik
Accepted Solution
Rabobank
SE
Thanks for your reply. I used JAVA step to check if a particular file exists,
PRFile folder = new PRFile("file://web:/StaticContent/global/ServiceExport/");
PRFile[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].toString().equals("file://web:/StaticContent/global/ServiceExport/AgeOfLoanReport.csv")){
APPName = "true";
}
Based on the APPName i am continuing my activity.
Ravi Kiran patnaik
US
This is nice to know. But I have a question from your Java step - How do we pass a file Name dynamically? do you have any idea?
E.g., if (listOfFiles[i].toString().equals("Dynamic file name should be used"))
Also, did you guys tried @Default.DoesFileExist(Filename) OOTB function?
Appreciate your answers !!
Pegasystems Inc.
GB
Regarding a dynamic filename; you could do this (assuming you are embedding this Java code into a PRPC Activity):
1. Add a String Parameter to your Activity (say 'Filename').
2. Add a corresponding String 'Local' (at the bottom of the Parameter tab) - 'Filename' is also suitable (they have different scopes).
3. Use a Property-Set step with 'Local.Filename' on the Left Hand side, and 'Param.Filename' on the Right Hand Side.
[You probably want to check that you Param is actually set at this point; use a 'PRE-STEP' WHEN condition]
4. In your Java step; you can refer directly to 'Filename' (since that what the 'Local' Definition does).
If you need pass OUT anything; you can do the same string in reverse; use a Property-Set with the Param value on the Left Hand Side, and Local value on the right hand side.
Pegasystems Inc.
GB
I built an example of what I meant above:
Here's the steps expanded (except the Java step - which I will show the code a little further down):
Here's a 'safety-check': the WHEN pre-condition to detect an empty Param (this just exits the Activity , but really it would branch to a handler in the Activity):
Here's the PARAM (+Locals) TAB:
I built an example of what I meant above:
Here's the steps expanded (except the Java step - which I will show the code a little further down):
Here's a 'safety-check': the WHEN pre-condition to detect an empty Param (this just exits the Activity , but really it would branch to a handler in the Activity):
Here's the PARAM (+Locals) TAB:
Here's the Code for the Java Step (note; you don't have to loop through all the files; you can instantiate the 'PRFile' and THEN check it exists [just like the Java 'File' Object in fact]):
PRFile testfile = new PRFile("file://web:/StaticContent/global/ServiceExport/"+Filename);
if ( testfile.exists() ) {
WellDoesIt="Yes, it does";
}
else
{
WellDoesIt="Nah mate, it don't";
}
I also tried the OOTB Library Function "Default.DoesFileExist", but this apparently looks for a FULL path'd file - and I couldn't figure out how to (safely) get this to look at 'ServiceExport'...
Legato Health Technologies LLP
IN
Hi All,
I am exporting the product zip file using prpcserviceutil on AIX system but not able to locate path:
file://web:/StaticContent/global/ServiceExport/
Can any one please help with this.
Thanks,
Bhushan
Pegasystems Inc.
US
This will be available in your app/web server temp folder, for example in my case in tomcat server -> C:\tomcat722\temp\StaticContent\global\ServiceExport