Created
November 15, 2018 20:37
-
-
Save ondrej-kvasnovsky/b70e94fc8282235013ed9dbb99e129aa to your computer and use it in GitHub Desktop.
S3 bucket structure to HTML
This file contains hidden or 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('mz/fs'); | |
const read = async() => { | |
const root = '/Users/testing-s3-2/' | |
let html = `<html><table style="width:100%" border="1">` | |
const folders = await fs.readdir(root); | |
for (const folder of folders) { | |
if (!fs.lstatSync(folder).isDirectory()) continue; | |
if (folder.startsWith('.') || folder.startsWith('node_modules')) continue; | |
html += '<tr>' | |
html += `<td valign="top"><a href="http://${folder}">${folder}</a></td>`; | |
const subFolders = await fs.readdir(root + folder); | |
for (const subFolder of subFolders) { | |
// console.log(subFolder); | |
if (fs.lstatSync(root + folder + '/' + subFolder).isDirectory()) { | |
const files = await fs.readdir(root + folder + '/' + subFolder); | |
for (const file of files) { | |
//console.log(file); | |
html += `<td><div>${subFolder}</div><img src="${folder}/${subFolder}/${file}" width="200px"/></td>`; | |
} | |
} | |
} | |
html += '</tr>' | |
} | |
html += '</table></html>'; | |
await fs.writeFile('./index.html', html); | |
} | |
read(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment