We have an interface file that we want to delete for security reasons once we have processed the file. But, deleting it from the Application Engine was not as straight-forward as I would have thought.
This does not work:
RemoveDirectory("c:\temp\mytextfile.txt", %FilePath_Absolute);
So, Java to the rescue — this does:
Local JavaObject &javaFile; &javaFile = CreateJavaObject("java.io.File", "c:\temp\mytextfile.txt"); &javaFile.delete();
Update (8/20/2014):
Back when I wrote this post, I missed seeing the .Delete() method of the File API object. That would be the better way to make this work. Here’s an example:
Local File &file; &file = GetFile("c:\temp\mytextfile.txt", "W", "A", %FilePath_Absolute); &file.Delete();
(Thanks Tim and Andrew for pointing this out.)
Resources
- JavaDocs for File
- JavaDocs for the delete() method
- RemoveDirectory function (update 12/7/2012: linked to Oracle’s PeopleBooks)
Thanks, very nice. Something different, instead of using the delete method of the file object.
I tried the code, that you mentioned but somehow I am getting Java class not instantiated error. Is there some setup needed for this?
You have quite good tips and I saw some more at http://www.itwisesolutions.com/PsftTips.html website.
thnks
Larry
Larry,
I am so sorry that I have taken so long to respond. I don’t know if you figured this out, but I could make a guess.
I get Java errors when I am running AE programs directly from App Designer. When I run them from online (via the batch server), they seem to run with no problem.
Is it possible that you are running it from App Designer? I hope that helps.
Excellent solution. It worked great for me. I used EXEC to delete a file and I was not able to. Not sure why it was not working but Java option worked well..
Thanks a lot digitaleagle.
Thanks for the tip. I’ve used the following and it work well to.
&tmpfile = GetFile(“c:tempfile.txt”, “W”, “A”, %FilePath_Absolute);
&tmpfile.Delete();
Thank
Tim
Great solution… Thanks a lot.
RemoveDirectory(“c:tempmytextfile.txt”, %FilePath_Absolute);
– would definitely not work because it looks like you want to delete a directory whereas you set the path up to a filepath… RemoveDirectory only deletes the Directory assuming no files exists in it.
Yes, apparently I missed the Delete() method of the File object. I think I was looking for just a regular PeopleCode function that would do the trick.