• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
        • File Statement
        • File.open Function
        • File.close Function
        • File.read Function
        • File.write Function
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization 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.read Function

Format
b = file_handler.read(string_variable ‖ string_list);
Description
The File.read function reads one or more lines of text from the File associated with file_handler. After the read the file pointer is positioned to the next line in the file. This function reads lines sequentially. This function is equivalent to the fileread function.
If a string_variable is provided as a argument, a single line of text is read and placed in the variable, which is either a temporary string variable or an alphanumeric dictionary item. If the dictionary item is longer than the line of text, blanks will be added at the end. If the item is shorter, the line of text will be truncated.
Alternatively, a string List can be used as an argument. In this case, all remaining lines in the file are read and stored in string_list.
File text can also be read using the File.readText and File.readLines actions.
Return Value
The function returns a logical value of 1 (true) if successful and 0 (false) otherwise.
Example
File occupation_codes_file;

occupation_codes_file.
open("Occupation Codes.txt");

// approach 1
string code;

while occupation_codes_file.read(code) do
   
// do something with the single code
enddo;

// approach 2
List string all_codes;

occupation_codes_file.
read(all_codes);
// do something with all of the codes

occupation_codes_file.
close();
See also: File Object, File.write Function, FileRead Function, File.readText Action, File.readLines Action