Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ondrej-kvasnovsky/b70e94fc8282235013ed9dbb99e129aa to your computer and use it in GitHub Desktop.
Save ondrej-kvasnovsky/b70e94fc8282235013ed9dbb99e129aa to your computer and use it in GitHub Desktop.
S3 bucket structure to HTML
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