Question

Create Folder Automatically

Hi,

I'm having a requirement like this ,

1. Create folder into desirable directory with custom format

2. Then, create new txt file inside on the folder created on step 1

Is this possible?

Thanks for your kindness ..

Regards

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

Correct Answer
December 23, 2017 - 9:12am

Hi, 

I observed in logs that the error -"The system cannot find the path specified" is coming up. So, now first I created a folder and then in the same folder, I created my desired file. I have verified the code at my end and it seems to create "Folder" and "File" as well. Just that first I will create a folder and then file. 

Please see the attached code and let me know if this works at your end as well. 

Regards,

Rachit

 

Comments

Keep up to date on this post and subscribe to comments

December 21, 2017 - 7:41am

Hi, 

You can write an activity. In this activity, write a java step.  Use the below code in that step. 

File myFile = new File("D://XYZ/myFile.txt");

try {
    flag = myFile.createNewFile();
} catch (IOException ioe) {
 olog.infoForced("Error while Creating File in Java" + ioe);
}

olog.infoForced("file" + myFile.getPath() + " created ");

}

This will automatically create a folder name XYZ and myfile.txt inside this folder. 

Please let me know if this resolves your issue.

Regards,

Rachit

 

December 22, 2017 - 2:55am
Response to Rachit_Agarwal

Hi Rachit thanks for your answer,

I'm already trying your code and it show error code like the attachments (picture number 1 until 3) that i'm already upload ..

And i'm already trying to modify your code and not having error (picture number 4) , but it can't create the folder and etc. Maybe another solution or somewhat like that?

Thanks.

Regards

December 23, 2017 - 8:37am
Response to RevianP1

I have modified the code and it is getting compiled successfully at my end. Please use below code. 

boolean flag=false;
java.io.File myFile = new java.io.File("D://XYZ//myFile.txt");

try {
    flag = myFile.createNewFile();
} catch (java.io.IOException ioe) {
 oLog.infoForced("Error while Creating File in Java" + ioe);
}
oLog.infoForced("file" + myFile.getPath() + " created ");

Let me know if this resolves the issue.

December 23, 2017 - 9:12am
Response to Rachit_Agarwal

Hi, 

I observed in logs that the error -"The system cannot find the path specified" is coming up. So, now first I created a folder and then in the same folder, I created my desired file. I have verified the code at my end and it seems to create "Folder" and "File" as well. Just that first I will create a folder and then file. 

Please see the attached code and let me know if this works at your end as well. 

Regards,

Rachit

 

December 27, 2017 - 8:36pm
Response to Rachit_Agarwal

Hi Rachit ,

Thanks for your answer. Now i'm already trying your given code but still can't get the result like you do. I'm trying your code with java step on activity, and call the activity using run activity or refresh this section on a button.

Maybe you can share with me how the step you procure to get the result , Thanks.

 

Regards,

Revian

December 27, 2017 - 11:00pm
Response to RevianP1

Hi,

Please check the parent directory permissions if you are using Linux  OS, please grant 777 permissions and check once.

December 27, 2017 - 11:09pm
Response to SudhakarReddy

Hi SudhakarReddy,

Thanks for your response. Fyi, i'm using windows OS .. and trying on other directory except the system but still not created.

 

Regards

December 27, 2017 - 11:35pm
Response to RevianP1

I used a run-Activity on a click-event inside a section and it is working perfectly for me. Please find the attached screenshots for reference. Please excuse the names used in screenshots. If it is not working for you, can you please check the PegaRULES log file and see if the java step fails there. Alternatively, you can have a look at RegaALERT logs and see if anything is generated there, though I am not sure if anything will come up there. 

December 28, 2017 - 2:20am
Response to Rachit_Agarwal

Hi Rachit,

Thanks for your time .. when i'm using tracer , it show good at java step and here the log file when running the activity (check attachments, thanks).

December 28, 2017 - 3:01am
Response to RevianP1

In the log file, it is clearly seen that the file/folder is created successfully. There are no exceptions regarding that. Then, in this scenario, I don't think there is an issue from PRPC side. Can you please check the privileges.

December 28, 2017 - 4:08am
Response to Rachit_Agarwal

Hi Rachit,

yeah , it's created successfully based on the log file. But still not created on my directory (you can see the attachment).

You suggest me to check the privileges, on PEGA Access group privilleges or on my PC? Can you give some example of the privilleges you have so can make you create the folder? Thanks

Regards..

December 28, 2017 - 5:39am
Response to RevianP1

Where is your server located? I think it is working for me because I have a server on my local machine itself and use case I am running on my machine itself. So can try and create a folder/file in the server location.

December 29, 2017 - 2:51am
Response to Rachit_Agarwal

Hi Rachit,

I'm already check about that issued, and it's (the folder) placed on the server side .. Thanks for your time and solving my case.

Regards,

Revian