I'm currently trying to write a script hook for dropped images which will automatically copy the dropped file(s) into a different directory relative to the rube file. The problem is that readFile and writeFile don't seem to support reading/writing binary files (like images). I also can't seem to find a way to do a system call so that I could copy the files that way instead.
Here's my script to illustrate what I'm trying to do:
Code: Select all
image[] img = getDroppedImages();
string imgDest = "assets/images/";
const uint numImg = img.length();
for(uint i=0; i<numImg; i++){
	string src = img[i].getFile();
	print("processing: " + src);
	
	int idx = src.findLast("/");
	string filename = src.substr(idx + 1);
	string dest = imgDest + filename;
	print("\tSaving to: \""+dest+"\"");
	if(fileExists(dest)){
		if(!queryYesNo("The file \"" + dest + "\" already exists. Overwrite destination?")){
			continue;
		}
	}
	writeFile(dest, readFile(src)); //this doesn't work
}