readFile()

Parent Previous Next

TW.readFile(QString)


var fileResult = TW.readFile("path/to/file.txt");



       relative paths are taken to be relative to the folder containing the
       executing script's file


The return value fileResult is an object (a map) with three member properties.


(You can use any valid variable name and not just fileResult)


status, result, and message

status


         fileResult.status

       fileResult['status']


gives you the status code (same as for writeFile).

Upon success       res.status == 0


See Return Values for Status

result


       fileResult.result  contains the text of the file.

This would be   undefined   if there is no content.


message


fileResult.message will have one of the following responses in it:


      1. "Reading all files is disabled (see Preferences)"
      2. "The file \"%1\" could not be opened for reading"


And upon successful reading of file content:

      1. undefined


Lua


In lua,  fileResult.status


And so on.


Python


In Python, the members are accessed as a dictionary   fileResult['status']


And so on.


Permissions


There is a setting for 'reading' permissions in the preferences dialog.


By default, global reading is disabled.


Files in the folder containing the

current script (e.g., <resources>/scripts/test/) and its sub folders are

always readable, as are files in the folder containing the current

target (tex/pdf) file's directory, its root (master) file's directory (if

used), and their sub folders.



Reference:        Stefan Löffler        http://tug.org/mailman/htdig/texworks/2010q4/003471.html

                 Stefan Löffler        http://tug.org/pipermail/texworks/2010q4/003531.html

               cpp                TWScriptAPI::readFile

Created with the Personal Edition of HelpNDoc: Full featured Documentation generator