Jump to content

[SOLVED] copy file function


photo

Recommended Posts

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

Link to comment
  • 1 month later...

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);
}
Link to comment

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

Link to comment
  • 2 months later...
×
×
  • Create New...