Jump to content

[SOLVED] copy file function


photo

Recommended Posts

Posted

there is a move file / rename file or delete file but missing copy file function.

So I can easily copy one file from one dir to another dir.

Also if there is a simliar function engine.filesystem.getFileName for file system will be great.

Because i want to use it in usc script. right now it's very hard to locate the assets from the relative path as some assets are inside a directory which not show in the path. example:

valley demo assets are relative to valley folder but the vally actually inside demos folder.

 

I need this 2 features for an assets packing tool

  • 1 month later...
Posted

Hello Yang,

 

We're working on node export tool which will be able to export assets from one project to another. As for copy function, there's no function like that in script API yet it's very simple to write one in the script.

 

Or you can use this code:

int copy_file(string old_path,string new_path) {
	File input = new File();
	
	if(input.open(old_path,"rb") == 0) {
		delete input;
		
		return 0;
	}
	
	File output = new File();
	if(output.open(new_path,"wb") == 0) {
		input.close();
		delete input;
		
		delete output;
		
		return 0;
	}
	
	long target_size = input.getSize();
	long actual_size = output.writeStream(input,target_size);
	
	input.close();
	delete input;
	
	output.close();
	delete output;
	
	return (target_size == actual_size);
}
Posted

hi Andrey:

    That's what i did after suggested by Ulf. it's a workaround. but i just think it would be included in the api since it's very basic file operation.

 

thanks

  • 2 months later...
Posted

In the meantime if you are on Windows or Linux you can grab the file copy function from Oilrush :)

×
×
  • Create New...