• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to read and loop throught datas in TSV file in extendScript?

Contributor ,
Oct 27, 2020 Oct 27, 2020

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..

TOPICS
Expressions , How to , Scripting

Views

348

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Oct 28, 2020 Oct 28, 2020

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
...

Votes

Translate

Translate
Community Expert ,
Oct 27, 2020 Oct 27, 2020

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines