SonicVoom
asked on
generate html from directory and file structure in bash or javascript
I have a directory containing several other directories that contain files. I need to turn these into HTML.
How could I wrap each sub-folder in a <UL> and each filename in <li> ?
I'd like this to be in bash or javascript.
How could I wrap each sub-folder in a <UL> and each filename in <li> ?
I'd like this to be in bash or javascript.
in bash yes, in js you need to pass the folder structure to the script
ASKER
Bash then. or PHP...
If you can get the structure into JSON format, as in the root variable below, then it should be fairly simple:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var root = [
{
name: "DiectoryA"
},
{
name: "DiectoryB",
children: [
{ name: "FileA" },
{
name: "DiectoryB2",
children: [
{ name: "FileA-B2" },
{ name: "FileB-B2" }
]
},
{ name: "FileC" }
],
},
{
name: "DiectoryC"
}
];
jQuery(document).ready( function() {
$("#container").append( render( root ) );
});
function render( parent ) {
var result = $( "<ul/>" );
for( var directory in parent ) {
$(result).append( $( "<li/>" ).text( parent[directory].name ).append( render( parent[directory].children ) ) );
};
return result;
}
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
ASKER
I don't know how to read it all into JSON. It's more the reading part that I'm confused by than the formatting.
Check this page : http://code.google.com/p/sitemap-generators/wiki/SitemapGenerators
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No submitted solution solved my question, this was the result of my googling.