{"name":"preprocessFile","operator":null,"title":"preprocessFile","type":"command","url":"https://community.bistudio.com/wiki/preprocessFile","revid":349792,"updated":"2023-11-20T22:10:15Z","groups":["System"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.85"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.85"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Reads and processes the content of the specified file. Preprocessor is C-like, supports comments using `//` or `/*` and `- /` and PreProcessor Commands.\nDue to the hard-drive access this command executes and the lack of caching this command should not be used in time-critical script loops.\n\n> [!WARNING]\n> If the file you are loading is not prepared using UTF-8 encoding and contains some characters with codes > 127, they might convert incorrectly.","syntaxes":[{"syntax":"preprocessFile fileName","since":null,"effect":null,"exec":null,"params":[{"name":"fileName","type":"String","optional":false,"default":null,"description":"path to the file and name of the file","types":["String"],"since":null,"text":"fileName: String - path to the file and name of the file"}],"returns":{"type":"String","types":["String"],"description":null,"text":"String"},"form":"unary","operator":null,"left":null,"right":{"text":"fileName","types":["String"]}}],"examples":[{"text":"```sqf\n_content = preprocessFile \"myFunction.sqf\";\n```","code":["_content = preprocessFile \"myFunction.sqf\";"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["fileExists","preprocessFileLineNumbers","loadFile","Function","SQF Syntax","call","spawn","execVM","PreProcessor Commands"],"notes":[{"user":"Alef","date":"2008-03-04T22:35:00Z","text":"File path is always relative to mission directory. If script dir\\a.sqf includes dir\\b.sqf, use \"dir\\b.sqf\" and not \"b.sqf\"."},{"user":"Kju","date":"2011-07-08T10:59:00Z","text":"Use preprocessFileLineNumbers instead as it provides more context information on error."},{"user":"Killzone_Kid","date":"2013-12-17T13:44:00Z","text":"The main difference between preprocessFile and preprocessFileLineNumbers is that the latter adds #line directive to the target file, which allows to log the `__LINE__` error happened at and the `__FILE__` error happened in."},{"user":"BrotherhoodOfHam","date":"2014-07-25T18:43:00Z","text":"Essentially what the preprocessFile command does is it refers to the contents of a file as a string:\n\nExample 1:\n\nboop.html:\n\n```html\n<t align = 'center' valign = 'middle' shadow = '0' size = '2'>structured text</t>\n```\n\ninit.sqf:\n\n```sqf\n_text = parseText preprocessFile \"boop.html\";\nhint _text;\n```\n\nThis is especially useful for long strings, and it works on files with any file extension as long as they can be edited with a text editor.\n\nExample 2:\n\ninit.sqf:\n\n```sqf\nhint preprocessFile \"description.ext\";\ncopyToClipboard preprocessFile \"mission.sqm\";\n```\n\nThe above is all valid. However, using *.jpg or any other files saved in an image format is not possible."}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: System","Introduced with Operation Flashpoint version 1.85","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}