Question

4
Replies
3109
Views
Sruthi Emmidi (SruthiEmmidi)
Amazon

Amazon
IN
SruthiEmmidi Member since 2015 10 posts
Amazon
Posted: March 15, 2017
Last activity: October 16, 2018
Posted: 15 Mar 2017 0:23 EDT
Last activity: 16 Oct 2018 12:03 EDT
Closed
Solved

Copy directory from one location to another location

Hi

I am trying copy a folder which has sub-folders inside it from one location to another location on the same server. I am using the below Java code to iterate through the files in the sourceDir and copy it in teh DestDIr. However, it is deleting the source directory, meaning, it is not copying but moving. It is moving the directory only if the directory has files and doesnt have sub-folders.

Is there any method I can use;

1. To copy the sub-folders as well (I tried using copyFolder method of Java 'File', but not working in Pega. Is there any equivalent method?)

2. To copy the files (If 1 is not available withing Pega, i can recursively loop through the folders and achieve 1 using 2)

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {

java.io.File afile =new java.io.File(SourceDir + listOfFiles[i].getName());
afile.renameTo(new java.io.File (DestDir + listOfFiles[i].getName()));
}

Thank you!

**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.

Data Integration Java and Activities
Moderation Team has archived post, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Question, please write a new Question.