{"name":"fileExists","title":"fileExists","type":"command","url":"https://community.bistudio.com/wiki/fileExists","revid":352073,"updated":"2024-02-01T23:24:41Z","groups":["Program Flow"],"status":"ok","games":{"arma3":"2.02"},"since":"arma3 2.02","arma3_since":"2.02","description":"Checks if file on given path exists. Uses same path resolve code as loadFile.\n\n> [!NOTE]\n> Absolute paths are not supported, such as those generated using getMissionPath. Attempting to check an absolute path will result in this error in RPT logs:\n> `Invalid path (only relative paths supported): 'C:\\...'`","syntaxes":[{"syntax":"fileExists path","params":[{"name":"path","type":"String","description":"path to file","type_expr":"String"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"true if it exists, otherwise false"},"form":"unary","right":{"text":"path"}}],"examples":[{"code":["fileExists \"\\a3\\mySuperPath\\bestFileEver.paa\"; // returns false"]},{"code":["private _path = \"a3\\functions_f_mp_mark\\revive\\_addaction_revive.inc\";\nif (fileExists _path) then { loadFile _path } else { diag_log format [\"File (%1) does not exist!\", _path] };"]},{"code":["// Sometimes it might be better to check if a file exists instead of checking if path is empty (\"\")\nprivate _class = \"ModuleObjectiveRaceFinish_F\";\nprivate _picture = getText (configFile >> \"CfgVehicles\" >> _class >> \"editorPreview\");\nif !(fileExists _picture) then { _picture = getText (configFile >> \"CfgVehicles\" >> _class >> \"portrait\") };\nif !(fileExists _picture) then { _picture = getText (configFile >> \"CfgVehicles\" >> _class >> \"icon\") };\nif !(fileExists _picture) then { _picture = getText (configFile >> \"CfgVehicles\" >> _class >> \"picture\") };\nif !(fileExists _picture) then { systemChat \"No valid picture found!\" } else { systemChat _picture };"]}],"see_also":["loadFile","preprocessFile","preprocessFileLineNumbers"],"notes":[{"user":"Leopard20","date":"2022-01-01T16:29:30Z","text":"Returns true for empty strings: `fileExists \"\"; // true`"}]}