[Node.js] 파일목록 알아내기

KingU·2021년 11월 6일
0

Node.js

목록 보기
4/6
post-thumbnail

Node.js에서

내가 사용하는 데이터의 파일목록을 알고 싶을 때

Google에

Node.js file list in directory

를 검색하고


How do you get a list of the names of all files present in a directory in Node.js?
I'm trying to get a list of the names of all the files present in a directory using Node.js. I want output that is an array of filenames. How can I do this?

stackoverflow.com

여기에 접속한 후 예시코드를 확인


var testFolder = './data'; //지금 코드를 작성하고 있는 폴더 내의 data라는 폴더에 파일을 확인하고 싶음
var fs = require('fs');

fs.readdir(testFolder, function(err, filelist) { //파일목록을 filelist라는 변수로 지정
  console.log(filelist); //파일목록을 출력
})



결과값

[ 'CSS', 'HTML', 'JavaScript' ]

data라는 폴더 내의 파일목록을 배열로 저장해서 보여줌


시간이 헛되지 않는 글이 되겠습니다.
I'll write something that won't waste your time.

profile
원하는 것을 창조하고 창조한 것을 의미있게 사용하자

0개의 댓글