Made this little function for testing if a file exists. While there are some read file commands such as loadFile, preprocessFile and preprocessFileLineNumbers, they all will output error if file is not present. The same will happen if you want to exec or execVM a non existing file. However htmlLoad will not error, instead there is additional command provided that reports on success of html loading, ctrlHTMLLoaded.

2 things. This command needs HTML control, which is fine since we can create one dynamically, it also doesn’t really need HTML markup, can accept any file, so this is a plus. The function could look something like this:

KK_fnc_fileExists = { private ["_ctrl", "_fileExists"]; disableSerialization; _ctrl = findDisplay 0 ctrlCreate ["RscHTML", -1]; _ctrl htmlLoad _this; _fileExists = ctrlHTMLLoaded _ctrl; ctrlDelete _ctrl; _fileExists };

Examples of use:

hint str ("mission.sqm" call KK_fnc_fileExists); //true hint str ("mission.sqml" call KK_fnc_fileExists); //false

Just don’t forget that this could present some security risks in MP, so you can limit what extensions are allowed to be used with htmlLoad by adding

  • allowedHTMLLoadExtensions[] = {“htm”,”html”,”xml”,”txt”}; //for example

to server config and listing allowed extension. This will block command on both server and client. As for the dedicated server read EDIT below.

Enjoy,
KK

EDIT:  No display is available on dedicated to create control so no way of using htmlLoad. Might want to try custom extension if server check is needed.