2013-08-30 4 views
0

로컬 서버에 CSV 파일이 있습니다. 한 번에 CSV 파일의 총 행 수를 얻으려고합니다.하지만 할 수 없습니다. 이거 도와 줘.node.js를 사용하여 CSV 파일의 총 레코드 수를 얻는 방법

+0

보기 https://github.com/wdavidw/node-csv – Plato

+0

어쩌면이 작업을 수행합니다 : http://stackoverflow.com/a/12453463/711902 –

+0

제대로 작동하지 않습니다 .Csv 파일에서 전체 행을 가져 오려고합니다. 제 경우에는 "\ r"또는 "\ n"이 없습니다. – user2700253

답변

0

Plato가 제안한대로 라이브러리를 통해 CSV로 작업하십시오.

FWIW, 텍스트 파일의 길이를 얻을 수있는이 도서관에서

var content; 
// First I want to read the file 
fs.readFile('./local.csv', function read(err, data) { 
    if (err) { 
     throw err; 
    } 
    content = data; 
    processFile();   // Or put the next step in a function and invoke it 
}); 

function processFile() { 
    lines = content.split("\r"); // look up 
    rowCount = lines.length; 
} 
관련 문제