Site logo

CSV or tab delimeted TXT file

How to open a CSV file both on Mac and Windows:

if (isOSX()) {  
    var csvFile = File.openDialog('Select a CSV File', function (f) { return (f instanceof Folder) || f.name.match(/\.csv$/i);} );  
} else {  
    var csvFile = File.openDialog('Select a CSV File','comma-separated-values(*.csv):*.csv;');  
}

Read CSV function

function ReadInCSV(file) {
     var thisLine, csvArray,
	 fileArray = [];
	 
     file.open("r");
     file.seek(0, 0);
	 
     while (!file.eof) {
         thisLine = file.readln();
          csvArray = thisLine.split(",");
          fileArray.push(csvArray);
     }
 
     file.close();  

     return fileArray;  
}

 

Here are examples of scripts.