SA-MP Forums Archive
[FS Function] DoesFileExists - Check if file exists or not. By : Abhinav - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FS Function] DoesFileExists - Check if file exists or not. By : Abhinav (/showthread.php?tid=81509)



[FS Function] DoesFileExists - Check if file exists or not. By : Abhinav - abhinavdabral - 11.06.2009

So, here is my very first post of this forum. I was just wondering about that server crashes in some file processing scripts when it does not founds a specified file. So I just created a function named as DoesFileExists("filename.txt") - An example is given below :-
Code:
DoesFileExists(fname[]){
	new File:checkfile = fopen(fname[0],io_read);
	if(!checkfile){
	  return 0;
	}
	else{
	  fclose(checkfile);
	  return 1;
	}
}
Example :
Code:
#include <a_samp>

public OnPlayerConnect(playerid)
{
	if(DoesFileExists("ExampleFile.txt")){
		printf("exists");
	}
	else{
		printf("Not Exists");
	}
  	return 1;
}

DoesFileExists(fname[]){
	new File:checkfile = fopen(fname[0],io_read);
	if(!checkfile){
	  return 0;
	}
	else{
	  fclose(checkfile);
	  return 1;
	}
}
This example will print the message EXISTS / Not EXISTS in your console window of the server. The file is kept in scriptfiles folder in your SAMP Server directory. Like if your SAMP Server is here
C:\Program Files\Server SAMP

Then the file will be here

C:\Program Files\Server SAMP\scriptfiles\ExampleFile.txt

Tell me if stuck with my code.
Use it wherever you want to.
Steal, modify or do w/e you want.




Re: [FS Function] DoesFileExists - Check if file exists or not. By : Abhinav - Weirdosport - 11.06.2009

What is fexist for then?

https://sampwiki.blast.hk/wiki/Scripting...ons_Old#fexist


Re: [FS Function] DoesFileExists - Check if file exists or not. By : Abhinav - abhinavdabral - 12.06.2009

Ahh.. fexists...well .. I made my own fexists....