Problem copying BMP file from one folder to another

Posted By: jaknine

Problem copying BMP file from one folder to another - 09/04/08 00:26

In this current project I have it set up so F11 takes a screen shot. My SAVEDIR is set to "data" and all screen shots are automatically saved in there as that's how 3DGS works. Since I have other things in the data folder (settings files, etc.) that are also saved there by the engine, I want to have the screen shots in their own folder, like "screenshots".

I am using the following code. Basically it takes a sequentially numbered screen shot, puts it in the data folder, then copies it into the screenshots folder (I haven't written the part to delete the original yet; that's coming).

It all works great except that the resulting file in the screenshots folder is only 0k in file size. Something is going wrong somewhere and I can't seem to figure out where.

Can anyone spot the problem?

Thanks!

Code:
var shotfilehandle;
var shotfilehandle1;
var theShotNum;

STRING theScreenShot = "#64";
STRING theNewShot = "#64";

STRING theShotNumString ;

action take_shot(){
	
	str_cpy(theScreenShot, "image_");  
	str_cpy(theNewShot, "screenshots\\"); 

	shotfilehandle1 = file_open_read("shots.num");
	theShotNum = file_var_read(shotfilehandle1);
	file_close(shotfilehandle1);

	theShotNum += 1;

	wait(1);
	snd_play(camera_click,100,0);

	wait(1);        

	str_for_num(theShotNumString,theShotNum);
	str_cat(theScreenShot, theShotNumString);
	str_cat(theScreenShot, ".bmp");

	str_cat(theNewShot, theScreenShot);

	file_for_screen("image_.bmp",theShotNum);  // saves a screenshot with a sequential suffix
	
	shotfilehandle = file_open_write("shots.num");
	file_var_write (shotfilehandle, theShotNum);
	file_close(shotfilehandle);   

	file_cpy (theNewShot, theScreenShot);
 
	str_cpy(theScreenShot, "image_");  
	str_cpy(theNewShot, "screenshots\\"); 

	wait(1);
}

Posted By: testDummy

Re: Problem copying BMP file from one folder to another - 09/04/08 11:54

Perhaps, this will be of some help.
(Probably not.)
C-Script file copy;
tested
Use \\ as path separator and workdir (ifdef DEVELOP) and exedir (ifelse) respectively.
Code:
/************************************
	filef_copy
*************************************/
var file_nFrom = 0;
var file_nTo = 0;
var file_nByte;

function filef_copy(_sFrom, _sTo) {
	var ret1; ret1 = 0;
	file_nByte = 0;
	file_nFrom = 0;
	file_nTo = 0;
	if (_sFrom == 0) {
		return(0); 
	}
	if (_sTo == 0) {
		return(0);
	}

	file_nFrom = file_open_read(_sFrom);
	if (file_nFrom == 0) {
		error("!error filef_copy: file from not found!");
		return(0);
	}
	
	file_nTo = file_open_write(_sTo);
	if (file_nTo == 0) {
		error("!error filef_copy: file to not found!");
		return(0);
	}
	while(1) {
		file_nByte = file_asc_read(file_nFrom);
		if (file_nByte != -1) { 
			file_asc_write(file_nTo, file_nByte);
			ret1 += 1; 
		} else {
			break;
		}
	}
	file_close(file_nFrom);
	file_close(file_nTo);
	return(ret1);
}

Posted By: jaknine

Re: Problem copying BMP file from one folder to another - 09/05/08 23:23

Thanks for trying. The code still didn't work for me but I figured out a solution to my problem anyway.

The manual implies that the screen shots can only be saved into the SAVEDIR folder, but I found out that you can add a path with no problem. So instead of copying the file out of "data" and into "screenshots" I just save it to "screenshots" to begin with.

The manual also says that file_cpy only works within the SAVEDIR folder but it turns out you can use paths with that one also.

Anyway, thanks again. Problem solved.
Posted By: testDummy

Re: Problem copying BMP file from one folder to another - 09/06/08 14:46

It's good that the problem is solved.

Indeed, file_cpy seems to copy correctly from and to paths other than the save_dir.


© 2024 lite-C Forums