javascript - how solve long name folders path creation with node js -
this not question because answer maybe usefull else: i'm on windows , , testing purpose add create high number of folders in folder, use code ,
createfolder.js:
var fs = require('fs') var root = './root/' var start = 0 var end = 10000 while (start < end) { fs.mkdirsync(root+start) root +=start+'/' }
this huge mistake .
because of , unable delete root folder because of long path name, anoying.
so try few different method, includely 1 : how delete long path in windows.
but can't figure why did not work.
i embarassed.
but when did test , figured out able rename folder.
as i'm linux user remenber can move folder rename command.
then solution, can't did straight cause long.
so here litlle snippet in case
uid.js:
module.exports=function( ){ function s4() { return math.floor((1 + math.random()) * 0x10000) .tostring(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); }
repair.js:
var fs = require('fs') var uid = require('./uid.js') var root= __dirname+'\\renamed\\' var rootlength = root.split('\\') console.log(root,rootlength.length) var count = 0 var pathit = function(path){ if(fs.existssync(path) == true){ var dir = fs.readdirsync(path) if(dir.length > 0) { for(d in dir ){ if(fs.existssync(path+dir[d]) == true && fs.statsync(path+dir[d]).isdirectory() == true) { count++ console.log(count) pathit(path+dir[d]+'\\') }else{ console.log("count %s",count) console.log(path) } } }else{ if(path != __dirname){ var way = path.split('\\') console.log(way.length) while(way.length != rootlength.length) { console.log(way.length) var joinit = way.join('\\') if(fs.existssync(joinit) == true) {fs.renamesync(joinit,'./root/'+uid())} way.pop() } console.log(way) } } } } pathit(root)
with code walk through last created folder , full unc.
then move folder last 1 until first folder root, here able select them using ctrl+a in folder , delete it.
i hope helpfull anyone.
Comments
Post a Comment