Checking to See if a Data File Has Been Imported

From Q
Jump to navigation Jump to search

The following script checks to see if a data file has already been imported into the project and, if it has, it stops the script from running and tells the user “Run this script from a fresh copy of Q, with no project open.”:

assert(project.dataFiles.length == 0, "Run this script from a fresh copy of Q, with no project open.");
  • project.dataFiles returns the data files in the project as an array (which is basically a list).
  • project.dataFiles.length works out the length of the array of data files (i.e., counts the number of data files in the project).
  • project.dataFiles.length == 0 returns a true of the number of data files is 0 and a false otherwise.
  • assert(condition,message) checks that condition is true. If not your script will be aborted.

See also