본문 바로가기
Web/Node.js

[Node.js] 파일 경로 가져오기.

by HyunS_ 2021. 1. 30.
728x90

path 모듈의 메소드 이용해서 파일 이름, 폴더 이름, 확장자를 가져올 수 있습니다.

 

var path = require('path');

var fileName = "C:\\Users\\suris\\Downloads\\이슈사항.pptx";
var dirName = path.dirname(fileName);
var baseName = path.basename(fileName);
var extName = path.extname(fileName);

console.log("디렉토리: %s, 파일이름: %s, 확장자: %s", dirName, baseName, extName);


// 결과값
디렉토리: C:\Users\suris\Downloads, 파일이름: 이슈사항.pptx, 확장자: .pptx

 

728x90

'Web > Node.js' 카테고리의 다른 글

mac에서 node.js 설치하기.  (0) 2022.09.27
[Node.js] 웹 서버 만들기  (0) 2021.01.31
[Node.js] 파일 쓰기  (0) 2021.01.31
[Node.js] 파일 읽기  (0) 2021.01.31

댓글