Jump to content
M1ke_SK

check if file exist in mission folder

Recommended Posts

Hi,

 

I am searching for way to check if script exist in mission, and if does, execute it.

 

Example:

params ["_faction", "_mission"];

_path = format ["scripts\missions\%1\%2.sqf", _faction, _mission];

_condition = ""; //here put condition to check if file exist

if(_condition) then {
    //script exist
    [] call compile preProcessFileLineNumbers _path;
}
else {
    //script does not exist
};

Share this post


Link to post
Share on other sites

This is not really possible in a good way.

 

I think there's one way, and that's to use try-catch with loadFile

Result should be empty string if not exists, and also notice that you can't use backslash comments

Share this post


Link to post
Share on other sites

possible to run use it with preProcessFileLineNumbers ?

Share this post


Link to post
Share on other sites

I know very late answer but maybe useful for future readers.

 

Code:

_pth = "pathToFile.sqf";	// Works with images (.paa) aswell
if ((loadFile _pth) isEqualTo "") exitWith {};	// File does not exist

 

Hope I was able to help someone :)

  • Like 2

Share this post


Link to post
Share on other sites
1 minute ago, TheDusty01 said:

I know very late answer but maybe useful for future readers.

 

Code:


_pth = "pathToFile.sqf";	// Works with images (.paa) aswell
if ((loadFile _pth) isEqualTo "") exitWith {};	// File does not exist

 

Hope I was able to help someone :)

 

1.90 yay !

  • Like 1

Share this post


Link to post
Share on other sites

This works with external files too run on server but sadly requires -allowFilePatching to find them.

// initServer.sqf
authenticatedDevs = [];
publicVariable "authenticatedDevs";

_filePath = "\Authority\authenticatedDevs.sqf";

if !(loadFile _filePath isEqualTo "") then
{
	call compile preprocessFileLineNumbers _filePath;
} else
{
	diag_log format ["#### %1 WAS NOT FOUND ###", _filePath];
};

Not really a big deal as popup file not found only appears on server.

  • Like 2

Share this post


Link to post
Share on other sites

No more usable for me as it throws error :/ when no file found

Share this post


Link to post
Share on other sites
On 8/26/2018 at 1:40 PM, TheDusty01 said:

I know very late answer but maybe useful for future readers.

 

Code:


_pth = "pathToFile.sqf";	// Works with images (.paa) aswell
if ((loadFile _pth) isEqualTo "") exitWith {};	// File does not exist

 

Hope I was able to help someone 🙂

 

since 2.02 use:

fileExists

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×