• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
        • Compiler Mode
        • Variables
        • Alias Statement
        • User-Defined Functions
        • Array Object
        • Audio Object
        • Case Object
        • Document Object
        • File Object
        • Freq Object
        • Geometry Object
        • HashMap Object
        • Image Object
        • List Object
        • Map Object
        • Pff Object
        • SystemApp Object
        • ValueSet Object
      • Procedural Sections
      • Logic
      • Language Elements
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

File Object

Most files in CSPro are data files, whose structure is defined by a data dictionary are are used in logic by referring to their dictionary names. However, it is also possible to write to text files without an associated data dictionary. Lines of text can be written to a file or read from a file, and these files can also be used in export statements.
The physical name of the file can be specified in the Define File Associations dialog when the application is run, in a PFF file, or by using the File.open, open, or setfile functions.
Functionality
A File is a CSPro logic object and the following functions can be called via dot notation:
FunctionDescription
openAssociates the File object with an existing or a new file on the disk (equivalent to setfile).
closeCloses the open file (equivalent to close).
readReads one or more lines of text from the file (equivalent to fileread).
writeWrites one or more lines of text to a file (equivalent to filewrite).
 
getLabelReturns the symbol's label.
getNameReturns the symbol's name.
getJsonReturns the symbol's metadata and value represented in JSON.
getValueJsonReturns the symbol's value represented in JSON.
In addition to these object functions, File objects can be used as arguments to functions such as filecopy, filedelete, fileempty, fileexist, filename, filerename, filesize, open, and pathname.
Assignments
When a File object is used as an argument to a user-defined function, it is passed by reference.
Example
File login_times_file;
login_times_file.
open("Login Times.csv", append);
login_times_file.
write("%s, %s, %d", getdeviceid(), getoperatorid(), timestamp());
login_times_file.
close();