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

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.

Reply
#2

What is fexist for then?

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)