Thursday, March 7, 2013

Deleting files in a folder using PeopleCode

Almost everyday I spent some time to go through the posts in various PeopleSoft forums like ITToolbox. This helps me to learn new things, I can help others and get help when needed.

Similar to my previous post, this is also related to a question asked on this forum.

Question: How to delete a file through peoplecode through AE process?

Answer: Here is the PeopleCode which will do this.

 Local array of string &fNames;  
 Local file &myFile;  
 Local String &dir;  
 &dir = 'F:\Temp\' | %DbName | '\Email\UTI0XX\*';  
 &fNames = FindFiles(&dir, %Filepath_Absolute);  
 While &fNames.Len > 0  
 For &i=1 to &fNames.Len  
 &myFile = GetFile(&fNames.[&i], "w", %Filepath_Absolute);  
 &myFile.Delete();  
 End-For;  
 End-while;  

No comments: