javascript实现获取磁盘中a文件与b文件的相对路径

 1 var aPath = 'C:/programfiles/game/a'
 2         var bPath = 'C:/workspace/QQ/game/b'
 3         function positivePath(a, b) {
 4             var aArr = a.split('/')
 5             var bArr = b.split('/')
 6             for (var i = 0; i < aArr.length - 2; i++) {
 7                 if (bArr[i] != aArr[i]) {
 8                     bArr.splice(0,i)
 9                     return '../'.repeat(aArr.length - i) + bArr.join('/')
10                 }
11             }
12         }
13         console.log(positivePath(aPath, bPath))

 

posted on 2019-02-14 22:15  时光游弋  阅读(860)  评论(0编辑  收藏  举报