Copy link to clipboard
Copied
Hi,
I am using the below function to read csv file. Recently noticed this issue. I did not know why its happening.. is it related to eof reason or any other reason?
When the csv file end of the row is only "F" its not returning by the function. When the empty para or the text para is given to the next line of "F", its returned. Why its happening?? is there is any reason... How to handle this case?
CSV :
Empty Next Line (or) next line with contents:
Empty next line:
Next line is bold:
Code:
function readFiles(filStr,fileFlag,column1,column2,column3,column4,columnArr){
var readFil = File(filStr);
var rCnt = 0;
if(!readFil.exists){
return false;
}else{
var fileContnts = "";
readFil.open("r");
if(fileFlag == "TXT"){
fileContnts = readFil.read();
}else{
while(readFil.eof==false){
try{
zRead=readFil.readln();
var csvR = zRead.split(",");
if(rCnt != 0){
column1.push(csvR[columnArr[0]]);
column2.push(csvR[columnArr[1]]);
column3.push(csvR[columnArr[2]]);
column4.push(csvR[columnArr[3]]);
rCnt++;
}
}catch(e){}
rCnt = 1;
}
}
readFil.close();
}
}
Regards,
Sudha K
Copy link to clipboard
Copied
Hi,
Collect the concept from here:
var myFile = File.openDialog("Choose a tab delimitted txt file:");
if (!myFile){exit();}
var myArray = []
myFile.open('r');
while (myFile.eof==false){
var line=myFile.readln().split(",");
alert(line[0])
myArray.push(line[0]);
}
Selva
Copy link to clipboard
Copied
Hi Sudha,
The issue with your code is that you are using readln and since it reads lines demarcated by newline and the last line does not have a new line after it, that line is skipped.
A better way would be to read the whole file into a string and then split it up on new line character, something like mentioned below.
var f = new File("Path to your file")
f.open("r")
var c = f.read()
var a = c.split("\n") //In case the line ends with a new line character you will have a blank line in the last entry. Check it and purge it
Hope this helps
-Manan
Copy link to clipboard
Copied
Hi,
Thank you for your reply... But my doubt is , if I use the same code for the below case its working. How it is ??
Input CSV:
Result:
Is there is any reason behind the end character is "F"? Because if i append any character with that without any other changes its returning that row contents. How it is??
If its the reason, it should not return the last row contents know? is it right??
- Sudha K
Copy link to clipboard
Copied
You mean to say this new screenshot that you pasted reads all the lines using readln even if the last line is not terminated by a new line? If so send me the file i can have a look
-Manan
Copy link to clipboard
Copied
Yes... I don't know the reason for that so only posted to know the reason..
I don't know how to attach file here. I created this file in mas os textEdit.
Copy link to clipboard
Copied
Upload the file on dropbox or gdrive and post the link here.
Copy link to clipboard
Copied
When u using this kind of csv, is it working correctly for u?
Can u pls create csv using textedit ..
What is dropbox and post it here.. Can u pls explain the steps?
Copy link to clipboard
Copied
It works as expected and described by me in my first reply. I would like to see your document to understand what you are seeing different. Google dropbox you would find it is
Copy link to clipboard
Copied
Thank you for your reply..
Currently i could not able to access the url for dropbox. So i could not able to post the csv file.
Can i upload the file using forum by attach file?