Discussion
Cognizant
US
Last activity: 4 Oct 2018 11:08 EDT
Java File Moving from one folder to other folder in the directory
Hi I Need to write a java step where it picks one file from the specified location and process something from PEGA and then move back the file to some other location. any help would be appreciated
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
US
Hello,
Thanks for posting this information. Please share the source of this information and provide some context to help others understand it better.
From the information posted we would point you to explore integration options like using a file listener and parsing the information for use on the clipboard instead of a java step in an activity.
This PDN article provides additional information about the file service and listener capabilities. https://community.pega.com/integration/how-to-set-up-a-file-service-and-file-listener
Hello,
Thanks for posting this information. Please share the source of this information and provide some context to help others understand it better.
From the information posted we would point you to explore integration options like using a file listener and parsing the information for use on the clipboard instead of a java step in an activity.
This PDN article provides additional information about the file service and listener capabilities. https://community.pega.com/integration/how-to-set-up-a-file-service-and-file-listener
There is a wizard in version 7 that will create these underlying rules. There is a lesson and exercise in the SSA course with an example as well.
Your question involves a design question of significant scope that requires a more nuanced answer. Based on your particular example I suggest that you reach out to Pega Consulting for further assistance.
Tara
Pega Academy Support Team
Cognizant
US
Thanks for the reply. I have resolved the issue by using filname.moveTo function through Java
S&P Global Inc
US
Hi Viajay,
I am also having the same requirement but small change is once the file moved to Destination location, we need to delete the file from Source location. Can you please help me with the Java Code?
Thanks & Regards
Imran
Pegasystems Inc.
US
Can you check the below post.
CIBC
CA
Hi- I am not looking for deletion of file. I am looking for code which will modify few contents of the file and then write the content again to a different or same directory
Lloyds Banking Group
GB
Is that possible to export file from Pega server to our local destination?
Cognizant
US
String SourceDir = ((PegaAPI)tools).getSystemSettings().get("ABC","FileSourceDirectory");
String DestDir = ((PegaAPI)tools).getSystemSettings().get("ABC","FileDestDirectory");
java.io.File fd1 = new java.io.File(SourceDir);
java.io.File fd2 = new java.io.File(DestDir);
oLog.infoForced("The mentioned source directory " + "SourceDir "+SourceDir + " DestinationDirectory.."+ DestDir);
java.io.File[] listOfFiles = fd1.listFiles();
Err = false;
if (fd1.exists() && fd1.isDirectory()){
} else {
Err = true;
oLog.infoForced("The mentioned source directory " + "SourceDir "+SourceDir + " doesn't exists...");
}
if (fd2.exists() && fd2.isDirectory()){
} else {
Err = true;
// oLog.infoForced("The mentioned target directory " +"Java out "+outJavaDir + " doesn't exists...");
}
if (Err == false)
{
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String SourceDir = ((PegaAPI)tools).getSystemSettings().get("ABC","FileSourceDirectory");
String DestDir = ((PegaAPI)tools).getSystemSettings().get("ABC","FileDestDirectory");
java.io.File fd1 = new java.io.File(SourceDir);
java.io.File fd2 = new java.io.File(DestDir);
oLog.infoForced("The mentioned source directory " + "SourceDir "+SourceDir + " DestinationDirectory.."+ DestDir);
java.io.File[] listOfFiles = fd1.listFiles();
Err = false;
if (fd1.exists() && fd1.isDirectory()){
} else {
Err = true;
oLog.infoForced("The mentioned source directory " + "SourceDir "+SourceDir + " doesn't exists...");
}
if (fd2.exists() && fd2.isDirectory()){
} else {
Err = true;
// oLog.infoForced("The mentioned target directory " +"Java out "+outJavaDir + " doesn't exists...");
}
if (Err == false)
{
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
// After the info is saved for the above file, move the file to Hot directory...
java.io.File afile =new java.io.File(SourceDir + listOfFiles[i].getName());
afile.renameTo(new java.io.File (DestDir + listOfFiles[i].getName()));
}
}
}
The bolded line moves files from source to destination autmatically . The original file will not be in the source folder.
CIBC
CA
Hi, Do you have the code if I want to replace certain content of a file and then write the file in the new directory
Pegasystems Inc.
IN
Virtusa Corp.
US
For this type of requirement configure an File-Listener which reads the file when it is available or placed in that specific folder and read that file after that use Connect-FTP to push the file to destination folder