Page 1 of 1

How to copy a file or a folder ? :)

Posted: October 20th, 2005, 10:39 pm
by Ktoeto
Hi all!
Is there some way to copy files and folders? My script has to copy files of various types and the only way I know is to create temporary .bat files with xcopy bla-bla, execute them and delete.
Standart method File(path).copy(target) doesn't work in my script, I don't know why...
Thanks.

Posted: October 21st, 2005, 12:28 am
by Ktoeto
I've got a solution!
My friend have written for me a function of copying folders :)
If it is interesting for anybody, here it is:

function my_copy_dir(dest)
{
var dest_obj = new Folder(dest);
if(!dest_obj.exists)
{
dest_obj.create();
}
var files = this.getFiles();
for(var i = 0;i<files.length;i++)
{
files.copy2(dest_obj.absoluteURI+'/'+files.name);
}
}
function my_copy_file(dest)
{
  this.copy(dest);
}
Folder.prototype.copy2 = my_copy_dir;
File.prototype.copy2 = my_copy_file;

dirFrom = folderGetDialog('From');
dirTo = folderGetDialog('To');

c = dirFrom.copy2(dirTo);



P.S. How do you post text as a code? I mean green color and borders around text

Posted: October 21st, 2005, 4:48 am
by byronnash
To post as code, select the text and hit the "code" button above the editing box.

Code: Select all

test code;