{"name":"fileExists","operator":null,"title":"fileExists","type":"command","url":"https://community.bistudio.com/wiki/fileExists","revid":352073,"updated":"2024-02-01T23:24:41Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"2.02"}],"since":{"game":"arma3","name":"Arma 3","version":"2.02"},"arma3_since":"2.02","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"path","type":"String","optional":false,"default":null,"description":"path to file","types":["String"],"since":null,"text":"path: String - path to file"}],"returns":{"type":"Boolean","types":["Boolean"],"description":"true if it exists, otherwise false","text":"Boolean - true if it exists, otherwise false"},"form":"unary","operator":null,"left":null,"right":{"text":"path","types":["String"]}}],"examples":[{"text":"```sqf\nfileExists \"\\a3\\mySuperPath\\bestFileEver.paa\"; // returns false\n```","code":["fileExists \"\\a3\\mySuperPath\\bestFileEver.paa\"; // returns false"]},{"text":"```sqf\nprivate _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] };\n```","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] };"]},{"text":"```sqf\n// 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 };\n```","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 };"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["loadFile","preprocessFile","preprocessFileLineNumbers"],"notes":[{"user":"Leopard20","date":"2022-01-01T16:29:30Z","text":"Returns true for empty strings: `fileExists \"\"; // true`"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Program Flow","Introduced with Arma 3 version 2.02","Scripting Commands"]}