Created
August 7, 2018 03:17
-
-
Save itacirgabral/f001b52f6c384c5d22b61a4b6f968cf0 to your computer and use it in GitHub Desktop.
generate csv with hash ,path, name from directory
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') | |
const crypto = require('crypto') | |
const path2hash = p => crypto.createHash('sha256').update(p).digest('base64') | |
const basedir = process.argv.length > 2 ? process.argv[2] : process.env.PWD | |
const printout = x => process.stdout.write(x) | |
let csv = '\"hash\"\t\"path\"\t\"name\"' | |
printout(csv) | |
printout('\n') | |
const stopAt = Infinity | |
const dig = function dig (path, deep = 0) { | |
if (deep < stopAt) { | |
const here = fs.readdirSync(path) | |
const dirs = [] | |
here.forEach(e => { | |
const twig = path + '/' + e | |
if (fs.lstatSync(twig).isFile()) { | |
printout('\"' + path2hash(twig) + '\"') | |
printout('\t ') | |
printout('\"' + path.slice(basedir.length) + '\"') | |
printout('\t ') | |
printout('\"' + e + '\"') | |
printout('\n') | |
} else { | |
dirs.push(e) | |
} | |
}) | |
dirs.forEach(e => dig(path + '/' + e, deep + 1)) | |
} | |
} | |
dig(basedir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use
node folder2csv.js /path/to/directory > data.csv