|
Guest
Posts: n/a
|
wisefool said:
> John H. Guillory said:
>> On Mon, 19 Jan 2004 05:48:14 -0000, "wisefool" <>
>> wrote:
>>
>>> No reason in principle why VB apps can't be driven from the command
>>> line.
>> None, but considering the original author didn't publish the source
>> code to his program and you did, its a hell of a lot easier to modify
>> your script to add the tables than to get his to run from the command
>> line.... Besides The VB app is kinda ackward, you have to click to
>> load the entire contents of the directory into the file box, click to
>> load the next level down, etc. When you get to the directory you want
>> the program doesn't Yield events, so redrawing of the window is
>> frozen and windows remains in a semi-stable state until the web page
>> is generated (which in reality takes longer than I'd expect), no
>> progress bar or anything displayed (probably because the window
>> pretty much disappears until generation of the web page is
>> finished), then the web page is auto-launched.... Then you have to
>> double-click on the parent directory until you get back to the
>> parent of the directory you want next.... and repeat the process for
>> each directory you want to do....
>
> Try this John - copy between the hyphens and save as
> HTMLDIR.JS.
>
> _Read the header for how to use_
> Don't just double-click it or it will error and crash out! 
>
> Your virus program might pop up about this script, simply
> because it is overwriting files using WSH. It is not a virus. 
> You might have to disable script-blocking in NAV to get
> it to run.
>
> Notice:
> 1. No warranty expressed or implied. Use at own risk
> 2. Do your own due diligence first to determine the safety
> of running this script!
>
> ------------------------------------------START HTMLDIR.JS
> //
> // HTMLDIR.JS
> //
> // >> Version A <<
> // Posted on Usenet group
> // 24hoursupport.helpdesk
> // 20-JAN-2004 GMT.
> //
> // Requires MS JScript version 3 or
> // above. (Most modern Windows
> // OSes - fine already. Download
> // Microsoft WSH otherwise).
> //
> // Check the thread "Re: Dir listing
> // to html?" for latest versions.
> //
> // Written by wisefool
> //
> // Feel free to rewrite and reuse, but
> // please give credit where credit is
> // due.
> //
> // NO WARRANTY EXPRESSED OR IMPLIED.
> // USE AT OWN RISK.
> //
> // EDIT THE CONFIGURATION, HTML AND
> // FORMATTING SECTIONS TO YOUR HEART'S
> // CONTENT. BUT SAVE BACKUP COPY
> // BEFORE YOU BEGIN! YOU WILL NEED TO
> // KNOW HTML & JSCRIPT TO BE ABLE TO
> // MAKE ANY REALLY USEFUL CHANGES TO
> // STUFF OTHER THAN CONFIGURATION AND
> // HTML.
> //
> // HOW TO USE:
> //
> // DO NOT run the script by
> // double-clicking it or it will
> // not work. Must be run through
> // command line:
> //
> // Type:
> // CSCRIPT HTMLDIR.JS [<dir>]
> //
>
> /* CONFIGURATION */
> var confirm_with_user = true;
> // Makes script prompt user before
> // running - only disable this if you
> // are sure you won't run it in the
> // wrong place by mistake.
>
> var end_of_line_characters = "\r\n";
> // "\n" is for Unix style; "\r\n" Windows
> // & "\r" for Mac style
>
> var dir_separator_display = "/";
> var dir_separator_link = "/";
> // Note: use "\\" for \
>
> var recurse_subdirectories = true;
> var list_subdirectories = true;
>
> var html_file_name = "index.html";
> var link_prefix = "";
> var dir_link_suffix = "/"+html_file_name;
>
> var size_display_mode = "smart";
>
> var launch_browser_at_end = true;
>
> var file_sort = "Name";
> var file_sort_ascending = true;
> var file_sort_ignore_case = true;
>
> var dir_sort = "Name";
> var dir_sort_ascending = true;
> var dir_sort_ignore_case = true;
>
> var parent_link_in_sub_dirs= true;
> var relative_dir_naming = true;
> var list_sub_html_files = false;
>
> // ** launch_browser_at_end **
> // You can disable the browser
> // display by setting launch_browser_at_end
> // to false.
>
> // ** size_display_mode - for file size units: **
> // set to "smart" or "bytes" or "kbytes" or
> // "Mybtes" or "Gbytes"
>
> // ** file_sort and dir_sort **
> // sort can be on "Name", "DateLastModified",
> // "DateLastAccessed", "DateCreated", "Size",
> // "Type"
>
> // ** relative_dir_naming **
> // false - displayed directory names use naming
> // starting with drive letter
> // true - directory names displayed relative to
> // the top of tree folder
>
> // ** list_subdirectories **
> // says whether to list subfolders in each HTML
> // file
>
> // ** parent_link_in_sub_dirs **
> // says whether to generate 'back up tree'
> // links to parent folders (No back link
> // is generated for top folders in any
> // event)
>
> // ** dir_link_suffix **
> // This controls whether the links to parent
> // and subdirectories have "/index.html" or
> // something else useful tacked on the end.
>
> // ** list_sub_html_files **
> // Controls whether index.html's I subdirectories
> // are listed as separate files.
>
> /* Settings used for debug - leave as is */
> var link_add_subdir_paths = false;
> var output_to_files = true;
>
> /* HTML */
> // Put single-line bits of HTML in quotes (""), join it up
> // using + symbols, including variables where desired.
> // include the variable e for newlines:
> var e = end_of_line_characters;
>
>
> // This generates the HTML for the header of each
> // output document
> function HTML2start(dpath,dirtext,subpathadd,istop) {
>
> // Uncomment for XHTML 1.0 transitional
> // (comment others):
>
> return "<?xml version='1.0' encoding='iso-8859-1' ?>"+e+
> "<!DOCTYPE html PUBLIC "+
> "'-//W3C//DTD XHTML 1.0 Transitional//EN' "+e+
> "'http://www.w3.org/TR/xhtml1/DTD"+
> "/xhtml1-transitional.dtd'>"+e+
> "<html xmlns='http://www.w3.org/1999/xhtml'>"+e+
> "<head><title>"+dirtext+
> "</title></head>"+e+
> "<body><h1>"+dirtext+"</h1>"+e;
>
> // Uncomment for fudgey bare-bones HTML
> // (comment others):
>
> /*
> return "<html>"+e+
> "<head><title>"+dirtext +
> "</title></head>"+e+
> "<body><h1>"+dirtext +"</h1>"+e;
> */
>
> }
>
> // This generates the HTML for the link to
> // a parent folder
> function HTML4parentlink(dpath,subpathadd,istop) {
>
> return "<a href='"+link_prefix+dpath.replace(/\\/g,
> dir_separator_link)+
> dir_link_suffix+"'>"+
> "Back to parent directory</a><br/>"+e;
>
> }
>
> // This generates the HTML for the heading
> // for file listings
> function HTML4fileheading(subpathadd,istop) {
>
> return "<h2>Files:</h1>"+e;
>
> }
>
> // This generates the HTML for the heading
> // for folder listings
> function HTML4dirheading(subpathadd,istop) {
>
> return "<h2>Subfolders:</h2>"+e;
>
> }
>
> // This generates the HTML for the details
> // of a subfolder
> function HTML4dir(dname,
> dcreate,dmodify,daccess,subpathadd,istop) {
>
> return "<a href='"+(link_prefix+
> (link_add_subdir_paths ?subpathadd:"")).
> replace(/\\/g, dir_separator_link)+dname+
> dir_link_suffix+"'>"+dname+
> "</a>, modified "+dmodify+", "+
> "created "+dcreate+", accessed "+daccess+"<br/>"+e;
>
> }
>
> // This generates the HTML for when there
> // are NO subfolders
> function HTML4nodirs(dir_obj,subpathadd,istop)
> {
> return "No subfolders<br/>";
> }
>
> // This generates the HTML that goes between the
> // directory and file listing on the page, if
> // subfolder listing is on
> function HTMLbetweendirsandfiles(dir_obj,subpathadd,istop)
> {
> return "";
> }
>
> // This generates the HTML for the details of a file
> function HTML4file(fname,fsize,
> fcreate,fmodify,faccess,ftype,subpathadd,istop) {
>
> return "<a href='"+(link_prefix+
> (link_add_subdir_paths ?subpathadd:"")).
> replace(/\\/g, dir_separator_link)+
> fname+"'>"+fname+
> "</a>, size "+fsize+", modified "+fmodify+", "+
> "created "+fcreate+", accessed "+faccess+", "+
> "type "+ftype+"<br/>"+e;
>
> }
>
> // This generates the HTML for when there
> // are NO files
> function HTML4nofiles(dir_obj,subpathadd,istop)
> {
> return "No files in this folder.<br/>";
> }
>
> // This generates the HTML for the end of
> // each HTML document
> function HTML2end(dpath,subpathadd,istop) {
>
> return "</body></html>"+e;
>
> }
>
> /* FORMATTING */
> // Unless you're just going to switch between
> // d-Mmm-YYYY and m/d/YYYY date formats you
> // will need to know Jscript to edit this
> // section
>
> var months = new Array("JANUARY", "FEBRUARY",
> "MARCH", "APRIL", "MAY", "JUNE", "JULY",
> "AUGUST", "SEPTEMBER", "OCTOBER",
> "NOVEMBER", "DECEMBER");
>
> function formatFileDate(d) {
>
> // For d-Mmm-YYYY hh:mm leave this
> // uncommented (comment others):
> return d.getDate()+"-"+
> months[d.getMonth()].substr(0,1)+
> months[d.getMonth()].substr(1,2)
> .toLowerCase()+
> "-"+d.getFullYear()+" "+
> twodig(d.getHours())+":"+twodig(d.getMinutes());
>
> // For m/d/YYYY hh:mm leave this
> // uncommented (comment others):
>
> // return (d.getMonths()+1)+"/"+
> // d.getDate()+
> // "/"+d.getFullYear()+" "+
> // twodig(d.getHours())+":"+twodig(d.getMinutes());
>
> }
>
> function formatFileSize(s) {
> var dsm = size_display_mode.toLowerCase();
> var units = "k";
>
> if (dsm == "smart") {
> if (s<1024) units = "bytes";
> if (s>(1024*1024*.85)) units = "MB";
> if (s>(1024*1024*1024*.85)) units = "GB";
> }
> else if (dsm == "bytes") units = "bytes";
> else if (dsm == "Mbytes") units = "MB";
> else if (dsm == "Gbytes") units = "GB";
>
> if (units=="k")
> s=Math.round((s/1024)*10)/10;
> if (units=="MB")
> s=Math.round(s/(1024*1024)*100)/100;
> if (units=="GB")
> s=Math.round(s/(1024*1024*1024)*1000)/1000;
>
> return s+" "+units;
> }
> function formatFileName(file_name) {
> return file_name;
> }
> function formatDirName(dir_name) {
> return dir_name;
> }
>
> /* DO NOT EDIT ANYTHING BELOW HERE UNLESS
> YOU WANT TO REWRITE THE SCRIPT */
>
> /* HTML generator wrappers */
> function preHTML_wrapper(d_obj,subpathadd,istop) {
> var dpath = d_obj.Path;
> var dirtext;
>
> if (relative_dir_naming)
> {
> if (istop)
> {
> dirtext = "Top level folder";
> }
> else
> {
> dirtext = "Subfolder "+subpathadd.substr(0,
> subpathadd.length-1).replace(/\\/g,
> dir_separator_display);
> }
> }
> else
> {
> dirtext = dpath.replace(/\\/g, dir_separator_display);
> }
>
> return HTML2start(dpath,dirtext,subpathadd,istop);
> }
> function fileHTML_wrapper(f_obj,subpathadd,istop) {
> var fname = formatFileName(f_obj.Name);
> var fsize = formatFileSize(f_obj.Size);
> var fcreate =
> formatFileDate(new Date(f_obj.DateCreated));
> var fmodify =
> formatFileDate(new Date(f_obj.DateLastModified));
> var faccess =
> formatFileDate(new Date(f_obj.DateLastAccessed));
> var ftype = f_obj.Type;
>
> return HTML4file(fname,fsize,fcreate,
> fmodify,faccess,ftype,subpathadd,istop);
> }
> function dirHTML_wrapper(d_obj,subpathadd,istop) {
> var dname = formatDirName(d_obj.Name);
> var dcreate =
> formatFileDate(new Date(d_obj.DateCreated));
> var dmodify =
> formatFileDate(new Date(d_obj.DateLastModified));
> var daccess =
> formatFileDate(new Date(d_obj.DateLastAccessed));
>
> return HTML4dir(dname,dcreate,dmodify,daccess,subpathadd, istop);
> }
> function parentlinkHTML_wrapper(dir_obj,subpathadd,istop)
> {
> var dpath = dir_obj.Path;
> return HTML4parentlink(dpath,subpathadd,istop);
> }
> function postHTML_wrapper(d_obj,subpathadd,istop) {
> var dpath = d_obj.Path;
> return HTML2end(dpath,subpathadd,istop);
> }
>
> /* Validation (ENTRY POINT) */
> var args = WScript.Arguments;
> if ((!output_to_files) &&
> recurse_subdirectories) {
> WScript.Echo("Must reconfigure "+
> "(edit htmldir.js):");
> WScript.Echo("Cannot recurse "+
> "subdirectories unless output is to files");
> WScript.Quit(1);
> }
> if ((!output_to_files) &&
> launch_browser_at_end) {
> WScript.Echo("Must reconfigure "+
> "(edit htmldir.js):");
> WScript.Echo("Cannot launch "+
> "browser unless output is to files");
> WScript.Quit(1);
> }
> if (args.length>1 ||
> (args.length==1 && isHelpSwitch(args(0)))) {
> WScript.Echo("Syntax:");
> WScript.Echo("htmldir [<optional-path>]");
> WScript.StdErr.WriteLine("Note: "+
> "Edit configuration and HTML "+
> "at top of htmldir.js if desired.");
> WScript.Quit(1);
> }
>
> /* Prepare */
> var dir, fso, dir_obj;
> dir = WScript.CreateObject(
> "WScript.Shell").CurrentDirectory;
> if (args.length >= 1) dir = args(0);
> fso = WScript.CreateObject(
> "Scripting.FileSystemObject");
> dir_obj = fso.GetFolder(dir);
>
> /* Confirm run */
> if (confirm_with_user && output_to_files)
> {
> WScript.Echo("HTMLDIR utility ");
> WScript.Echo("");
> WScript.Echo("WARNING!");
> WScript.Echo("");
> WScript.Echo("May overwrite "+
> html_file_name+" in "+dir_obj.Path+
> (recurse_subdirectories?
> " and ALL directories below it":
> ""));
> WScript.Echo("if this/these exist.");
> WScript.Echo("");
> WScript.Echo("Proceed? [y/n then Enter]");
> buf = WScript.StdIn.ReadLine().toLowerCase();
> if ((buf!="yes")&&(buf!="y"))
> {
> WScript.Echo("Script aborted.");
> WScript.Quit(1);
> }
> if (dir_obj.IsRootFolder)
> {
> WScript.Echo("You are about to run on a top-level "+
> "folder (see above).");
> WScript.Echo("Are you absolutely sure "+
> "you want to do this?");
> WScript.Echo("");
> WScript.Echo("Proceed? [y/n then Enter]");
> buf = WScript.StdIn.ReadLine().toLowerCase();
> if ((buf!="yes")&&(buf!="y"))
> {
> WScript.Echo("Script aborted.");
> WScript.Quit(1);
> }
> }
> WScript.Echo("Fine. Running...");
> }
>
> /* Go! */
> if (output_to_files) {
> writeFile(dir_obj,html_file_name,
> pageHTML(dir_obj,"",true));
> } else {
> WScript.Echo(pageHTML(dir_obj,"",true));
> }
> if (recurse_subdirectories) {
> recurseSubFolders(dir_obj,"");
> }
>
> /* Launch browser? */
> if (launch_browser_at_end)
> {
> var dir_name = dir_obj.Path;
>
> if (dir_name.substr(dir_name.length-1,
> dir_name.length-1)!="\\") {
> dir_name = dir_name + "\\";
> }
>
> WScript.CreateObject("WScript.Shell").
> Run(dir_name+html_file_name);
> }
>
> /* Sorting functions */
> function directorySort(a, b)
> {
> var v1 = getprop(a, dir_sort.toLowerCase());
> var v2 = getprop(b, dir_sort.toLowerCase());
>
> if (dir_sort_ignore_case && typeof(v1)=="string") {
> v1 = v1.toLowerCase();
> v2 = v2.toLowerCase();
> }
>
> if (v1<v2) /* 1ST_IS_LESS */
> return dir_sort_ascending?-1:+1;
>
> if (v1>v2) /* 2ND_IS_LESS */
> return dir_sort_ascending?+1:-1;
>
> return 0;
> }
>
> function fileSort(a, b)
> {
> var v1 = getprop(a, file_sort.toLowerCase());
> var v2 = getprop(b, file_sort.toLowerCase());
>
> if (file_sort_ignore_case && typeof(v1)=="string") {
> v1 = v1.toLowerCase();
> v2 = v2.toLowerCase();
> }
>
> if (v1<v2) /* 1ST_IS_LESS */
> return file_sort_ascending?-1:+1;
>
> if (v1>v2) /* 2ND_IS_LESS */
> return file_sort_ascending?+1:-1;
>
> return 0;
> }
>
> function getprop(v, prop) {
> // slightly faster than eval(...)
> if (prop=="name") return v.name;
> if (prop=="size") return v.size;
> if (prop=="datelastmodified")
> return v.datelastmodified;
> if (prop=="datelastaccessed")
> return v.datelastaccessed;
> if (prop=="datecreated")
> return v.datecreated;
> if (prop=="type") return v.type;
>
> // failed
>
> WScript.Echo("Invalid dir_sort "+
> "or file_sort parameter; look at htmldir.js");
> WScript.Quit(1);
> }
>
> /* Rendering function */
> function pageHTML(dir_obj,subpathadd,istop) {
> var s, c, html, n, i;
> html = preHTML_wrapper(dir_obj,subpathadd,istop);
> if (parent_link_in_sub_dirs && !istop)
> {
> html = html + parentlinkHTML_wrapper(dir_obj.ParentFolder,
> subpathadd,istop);
> }
> if (list_subdirectories)
> {
> s = new Enumerator(dir_obj.SubFolders);
> var sd = new Array();
> for (n=0; !s.atEnd(); s.moveNext(), n++) {
> sd[n] = s.item();
> }
> html = html + HTML4dirheading(subpathadd,istop);
> sd = sd.sort(directorySort);
> for (n=0; n<sd.length; n++) {
> html = html + dirHTML_wrapper(sd[n],subpathadd,istop);
> }
> if (n==0) html = html + HTML4nodirs(dir_obj);
> html = html + HTMLbetweendirsandfiles(dir_obj,subpathadd,istop);
> }
> s = new Enumerator(dir_obj.Files);
> html = html + HTML4fileheading(subpathadd,istop);
> var sf = new Array();
> for (n = 0; !s.atEnd(); s.moveNext()) {
> i = s.item();
> if (!(
> (!list_sub_html_files) && i.Name==html_file_name
> )) {
> sf[n++] = i;
> }
> }
> sf = sf.sort(fileSort);
> for (n=0; n<sf.length; n++) {
> html = html + fileHTML_wrapper(sf[n],subpathadd,istop);
> }
> if (n==0) html = html + HTML4nofiles(dir_obj,
> subpathadd,istop);
> html = html + postHTML_wrapper(dir_obj,subpathadd,istop);
> return html;
> }
>
> /* Recursing function */
> function recurseSubFolders(dir_obj,subpathadd)
> {
> var en = new Enumerator(dir_obj.SubFolders);
> var sf, subpathadd1;
>
> for (; !en.atEnd(); en.moveNext()) {
> sf = en.item();
> subpathadd1=subpathadd+sf.name+"\\";
> writeFile(sf,html_file_name,pageHTML(sf,subpathadd 1,false));
> recurseSubFolders(sf,subpathadd1);
> }
> }
>
> /* Utility functions */
> function writeFile(d_obj,filename, html)
> {
> var ts = d_obj.CreateTextFile(filename,
> true, false);
> ts.Write(html); ts.Close();
> }
> function isHelpSwitch(sw) {
> sw = sw.toUpperCase();
> return (sw=="/?")||(sw=="-?")||(sw=="-H")||
> (sw=="/H")||(sw=="-HELP")||(sw=="/HELP")||
> (sw=="--HELP")||(sw=="--H");
> }
>
> function twodig(num)
> {
> var str = ""+num;
> if (str.length==1) str="0"+str;
> return str;
> }
> ------------------------------------------END HTMLDIR.JS
>
> wisefool
Performance on my system is not great:
To list 29,353 files in 1,474 HTML index files it took 14 minutes
with my script, just under 2 HTML files per second. How does this
compare to the VB programs when they are generating equivalent files?
I have a 2GHz machine with 512MB ram!
Flexibility comes at a price here I think.
wisefool
|
|