How to copy a file or a folder ? :)

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Ktoeto
Posts: 4
Joined: October 13th, 2005, 5:04 am
Location: Moscow, Russia

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.
Ktoeto
Posts: 4
Joined: October 13th, 2005, 5:04 am
Location: Moscow, Russia

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
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

To post as code, select the text and hit the "code" button above the editing box.

Code: Select all

test code;
Post Reply