Though Pega suggest us not to use java , certain times we are forced to use java for the complex solutions.
For a guy like me , who did not do java as curriculum always depends on google for the java code.
This post is going to help me to identify the syntax of certain java code which I have used
This post shows me how to check the files and folders in the server where pega is installed.
Since I don't have access to Pega production server directly , I have used Java here to display the list of files and folders in Pega logs.
This will help me to confirm if the file listener files are present in path or not.
try {
oLog.infoForced("[FilesInDirectory] try block started ");
java.io.File fileContents[] = new java.io.File(Path).listFiles();
if (fileContents != null) {
for (int i = 0; i < fileContents.length; i++) {
if (fileContents[i].isDirectory()) {
oLog.infoForced("[FilesInDirectory] Folder: " + fileContents[i]);
} else {
oLog.infoForced("[FilesInDirectory] File: " + fileContents[i]);
}
}
}
oLog.infoForced("[FilesInDirectory] try block Ended ");
} catch (Exception ex) {
oLog.error("[FilesInDirectory] catch block expected", ex);
}
try {
oLog.infoForced("[FilesInDirectory] try block started ");
java.io.File fileContents[] = new java.io.File(Path).listFiles();
if (fileContents != null) {
for (int i = 0; i < fileContents.length; i++) {
if (fileContents[i].isDirectory()) {
oLog.infoForced("[FilesInDirectory] Folder: " + fileContents[i]);
} else {
oLog.infoForced("[FilesInDirectory] File: " + fileContents[i]);
}
}
}
oLog.infoForced("[FilesInDirectory] try block Ended ");
} catch (Exception ex) {
oLog.error("[FilesInDirectory] catch block expected", ex);
}
Create a New Activity in Pega with parameter "Path" to pass to java step and Paste the above Java Code.
This activity contains only two steps . 1) First to set the Param.Path to Local.Path 2) Run the Java
Since I am running on my Local machine (windows) , I am passing the path as D:\InstallationApps\PRPCPersonalEdition\tomcat . If Its Linux ,we can just pass /opt
Now check the logs for the list of files and folders.