Saturday, May 5, 2012

Move and Delete files using PeopleCode

We can use the below java object and code to move or deleting files from some location.

Moving file:

Local JavaObject &source = CreateJavaObject("java.io.File", "/source/file.txt");
Local JavaObject &target = CreateJavaObject("java.io.File", "/target/file.txt");

&source.renameTo(&target);



Deleting file:

Local JavaObject &DelLoc = CreateJavaObject("java.io.File", "/source/file.txt");
&DelLoc.delete(); 
Alternate code for deleting file:
&tmpfile = GetFile(“c:\temp\file.txt”, “W”, “A”, %FilePath_Absolute);
&tmpfile.Delete();


 

3 comments:

Anonymous said...
This comment has been removed by the author.
Anonymous said...

HI,
I used :

Local JavaObject &source = CreateJavaObject("java.io.File", "/source/file.txt");
Local JavaObject &target = CreateJavaObject("java.io.File", "/target/file.txt");
&source.renameTo(&target);

This method is working fine . but the issue is I need bothe source and destination copy.

in this method , after moving the file , there is no copy file in my first folder .
Is there any copy file option are there in java ,, can be use in AE--peoplcode .
Even i used Putattachment function , Its throwing me an erro like :
An invalid parameter has been passed to the file attachment function. (2,788)

my code :PutAttachment(URL.A, &sFileName, GetURL(URL.B) | &sFileName)

please help me , I need file copy in both URL/folder.(Yes ,its generating file in url B)..

mike

A said...

Hi Mike - what was the resolution for copying file to another folder?

Post a Comment