Copy link to clipboard
Copied
I want to know how can we read data in a TSV file in extendscript and loop through the each column and rows inside TSV file.
for example have this simple tsv file in desktop.
ID Name AGE
1 XXXX 12
2 YYYY 13
3 ZZZZ 14
I want to loop each column and rows and alert them. How can I do it?
Thank you..
I created this workaround to read the data in TSV through scripting.
var tsvFile = new File('~/Downloads/SS.tsv');
tsvFile.open('r');
var columnTitle = tsvFile.readln();
var rowCount = tsvFile.read('r').toString();
tsvFile.close();
///////////////Column Counts
var columnData = columnTitle.split('\t');
var numOfColumns = columnData.length;
///////////////Row Counts
var rowData = rowCount.split('\n');
var numOfRows = rowData.length;
for(var r=0; r<numOfRows; r++){
for(var c=0; c<numOfColumn
...
Copy link to clipboard
Copied
Not sure if you can read directly through scripting, you can through expressions. I would say get the file path,
var filePath = app.project.rootFolder.items[1].mainSource.file;
read the file,
http://estk.aenhancers.com/file-system-access/file-object.html?highlight=.read#read
then parse the result with a parser online or write your own.
Copy link to clipboard
Copied
I created this workaround to read the data in TSV through scripting.
var tsvFile = new File('~/Downloads/SS.tsv');
tsvFile.open('r');
var columnTitle = tsvFile.readln();
var rowCount = tsvFile.read('r').toString();
tsvFile.close();
///////////////Column Counts
var columnData = columnTitle.split('\t');
var numOfColumns = columnData.length;
///////////////Row Counts
var rowData = rowCount.split('\n');
var numOfRows = rowData.length;
for(var r=0; r<numOfRows; r++){
for(var c=0; c<numOfColumns; c++){
columnName = columnTitle.split('\t')[c];
alert(columnName + " = " +rowData[r].split('\t')[c]);
}
}
This line of code will alert every items in row by row until all row and column finishes.