【发布时间】:2014-03-14 19:52:20
【问题描述】:
我有一个简单的方法来检查目录是否存在。我注意到,当调用 fs.lstat 时,它会创建一个类似于 临时文件 的文件,其名称类似于“12116-ocskz3”
lstat 为什么会创建这些临时文件以及如何删除它们?
self.checkDirectory = function (callback) {
fs.lstat(uploadDir, function (err, stats) {
// Linux fielsystem manual - http://linux.die.net/man/2/lstat
if (!err && stats.isDirectory()) {
//Directory exists
console.log('This directory already exists!');
if (typeof(callback) == 'function') {
callback(true, uploadDir);
}
} else if (err.code === 'ENOENT') {
// ENOENT - A component of path does not exist, or path is an empty string.
console.log(err.code + ': This directory doesn\'t exists!');
if (typeof(callback) == 'function') {
callback(false, uploadDir);
}
}
});
};
【问题讨论】: