Before that, you need to add a '.' In Front Of nodejs in windows '.'. This is strange. For example, '/Cache/t' cannot be directly written like this. It needs to be changed to './Cache/t '.
When mkdir is used in windows, a directory cannot be created at all. However, by comparing the example we wrote earlier, we found that when multiple paths exist, for example :'. /Cache/tt'. If there is no cache directory in the current directory, throw err will be executed in the function you write;
VaR FS = require ('fs'); FS. mkdir ('. /Cache/tt', 0776, function (ERR) {If (ERR) Throw err; // if no cache directory exists, an exception is thrown. The else {// my code // is executed when the cache directory exists }})
Through the analysis above YSS, we already know what to do below. Is to create a directory loop for each layer ~
See the following:Code:
/*** Nkdir for Windows (MD command) * @ Params is the same as the mkdir */function mkdirs (p, mode, callback) {callback = callback | function () {};/* First shoshould be. */If (P. charat (0 )! = '. ') {Callback (p); return;}/* Split it */var PS = P. split ('/'), Len = ps. length, I = 1, TMP; while (I ++ <Len) {TMP = ps. slice (0, I ). join ('/'); // console. log (TMP) // path. exists (TMP, function (exists) {// If (! Exists) {fs. mkdir (TMP, mode); // console. Log (I + ":" + TMP) //});} callback ();}
But when I write the above code, I find that it cannot be done through path. exists. If you remove the comment above. Output result:
E: \ code \ node> node e \ HTTP. JS. /cache. /Cache/PPT. /Cache/PPT/IMG. /Cache/PPT/img/imgloadlazy6 :. /Cache/PPT/img/imgloadlazy6 :. /Cache/PPT/img/imgloadlazy6 :. /Cache/PPT/img/imgloadlazy
It's strange ~
This issue needs to be found after YSS, I also hope that you can answer this Article .