Skip to content

Commit c9f74a6

Browse files
committed
判断文件是否存在并返回错误信息
1 parent f888d5c commit c9f74a6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎build/crawler.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ CreatMarkdown(from_path,to_path)
1818
function CreatMarkdown(from_path,to_path){
1919

2020
var new_to_path = path.join(path.dirname(__dirname),to_path)
21+
if(exists(new_to_path)) return console.log(" → error: 目录存在 ",to_path,'\n')
22+
2123
new_to_path = path.dirname(new_to_path)
2224
mkdirsSync(new_to_path,0777,function(){
2325

2426
request.get(from_path).end(function(err, res){
25-
console.log("to_path::",to_path)
27+
// console.log("to_path::",to_path)
2628
fs.writeFileSync(to_path, toMarkdown(res.text).toString() ,'utf-8');
2729
console.log(" → ",to_path)
2830
});
@@ -45,4 +47,8 @@ function mkdirsSync(dirpath, mode, callback) {
4547
callback&&callback(dirpath);
4648
}
4749
}
48-
};
50+
};
51+
52+
53+
//检查指定路径的文件或者目录,是否存在
54+
function exists(_path){return fs.existsSync(_path);}

0 commit comments

Comments
 (0)