Highlighted

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

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

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.

TOPICS
Expressions, How to, Scripting

Views

38

Likes

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

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

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

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.

TOPICS
Expressions, How to, Scripting

Views

39

Likes

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
Oct 27, 2020 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Oct 27, 2020 0
Contributor ,
Oct 28, 2020

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.

Likes

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
Reply
Loading...
Oct 28, 2020 1