Created
September 11, 2019 00:52
-
-
Save omgitsraven/efa3641c9d974b26b70976714ce22400 to your computer and use it in GitHub Desktop.
Use node.js to produce a list of all of the files below a certain directory, and their filesizes, for the sake of a quick-and-dirty diff across two machines that should be in sync.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
var root = process.argv[2]; | |
var result = ""; | |
var count = 0; | |
function readBelow(curRoot){ | |
var contents = fs.readdirSync(curRoot,{withFileTypes:true}); | |
for(var entry of contents){ | |
var pathToMe = curRoot+"\\"+entry.name; | |
if (entry.isDirectory()){ | |
readBelow(pathToMe); | |
} else { | |
var stat = fs.statSync(pathToMe,{bigint:true}); | |
var localPath = pathToMe.substr(root.length); | |
result += localPath+"\n"+stat.size.toString()+"\n"; | |
count++; | |
} | |
} | |
} | |
readBelow(root); | |
var replacedPath = root.replace(/[\\:]/g,'_'); | |
fs.writeFileSync(replacedPath+".txt",result); | |
console.log(count+" items found."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment