1
代碼:path.join爲TMPDIR返回兩個額外的標記(空字符串)
var tmp = path.join(os.tmpDir(), dir);
var segments = tmp.split(path.sep); // create directories/subdirectories
console.log(tmp);
for(var i=0; i<segments.length; i++) {
var segment = segments.slice(0, i).join(path.sep);
console.log(i, segment.length, segment, fs.existsSync(segment));
}
輸出:
/var/folders/ch/pc8wsx1x1_v10hdl7zxnvjqr0000gn/T/somedir
0 0 '' false
1 0 '' false
2 4 '/var' true
3 12 '/var/folders' true
問:
爲什麼指數在0和1是空字符串?
好的,這本應該寫成什麼樣的正確方法? – user2727195