Delete Multiple Files Using PeopleCode

Your rating: None Average: 4 (1 vote)

Deleting files sitting on a server using PeopleCode is one thing I'm sure you will be doing sometime during your PeopleSoft career. The code below should help you out and get you started!

/*The path to the files you need to delete*/
&oldFilesPath = "/my_directory/my_folder";
/*Notice the "*" at the end of the file name. This means any file that starts with "file_name" will be deleted*/
&oldFiles = "file_name" | "*";
&PathAndName = &oldFilesPath | &oldFiles;
/*Display file path and name to be deleted */
MessageBox(0, "", 0, 0, "Delete file: " | &PathAndName);
&oldFileNames = FindFiles(&PathAndName, %FilePath_Absolute);
/*Loop through files found and delete one by one */
While &oldFileNames.Len > 0/* Delete files one at a time */
&deleteFile = "../../../.." | &oldFileNames.Shift();
/*Display file path and name deleted */
&retcode = DeleteAttachment(URL, &deleteFile);
MessageBox(0, "", 0, 0, "Deleted file: " | &deleteFile);
/*Check delete status*/
If (&retcode = %Attachment_Success) Then

MessageBox(0, "File Attachment Status", 0, 0, "DeleteAttachment succeeded");
End-If;

If (&retcode = %Attachment_Failed) Then

MessageBox(0, "File Attachment Status", 0, 0, "DeleteAttachment failed");

End-If;

If (&retcode = %Attachment_Cancelled) Then

MessageBox(0, "File Attachment Status", 0, 0, "DeleteAttachment cancelled");

End-If;

If (&retcode = %Attachment_FileTransferFailed) Then

MessageBox(0, "File Attachment Status", 0, 0, "DeleteAttachment failed: File Transfer did not succeed");

End-If;
End-While;

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
The question below is to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.