{"name":"preprocessFile","title":"preprocessFile","type":"command","url":"https://community.bistudio.com/wiki/preprocessFile","revid":349792,"updated":"2023-11-20T22:10:15Z","groups":["System"],"status":"ok","games":{"ofp":"1.85","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.85","arma3_since":"0.50","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","params":[{"name":"fileName","type":"String","description":"path to the file and name of the file","type_expr":"String"}],"returns":{"type":"String","type_expr":"String"},"form":"unary","right":{"text":"fileName"}}],"examples":[{"code":["_content = preprocessFile \"myFunction.sqf\";"]}],"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:\nExample 1:\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.\nExample 2:\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."}]}