Dir listing to html?

Discussion in 'Computer Support' started by JesterDev, Jan 15, 2004.

  1. JesterDev

    JesterDev Guest

    Would anyone happen to know of a program that will
    take a directory listing on my hard drive, and convert
    it to html?

    I could do this by hand, but I thought maybe there was
    some software that might be able to do this.

    What I'm after is something that will just add links to
    the various files not the directories themselves.. Like

    file1.bas - Links to file1.bas
    file2.bas - links to file2.bas

    not g:\gwbasic\pub\utilities\file1.bas
    JesterDev, Jan 15, 2004
    #1
    1. Advertising

  2. JesterDev

    °Mike° Guest

    HDLG html directory list generator
    http://www.hdlg.info/


    On Thu, 15 Jan 2004 20:17:18 GMT, in
    <izCNb.75147$I06.329674@attbi_s01>
    JesterDev scrawled:

    >Would anyone happen to know of a program that will
    >take a directory listing on my hard drive, and convert
    >it to html?
    >
    >I could do this by hand, but I thought maybe there was
    >some software that might be able to do this.
    >
    >What I'm after is something that will just add links to
    >the various files not the directories themselves.. Like
    >
    >file1.bas - Links to file1.bas
    >file2.bas - links to file2.bas


    --
    Basic computer maintenance
    http://uk.geocities.com/personel44/maintenance.html
    °Mike°, Jan 15, 2004
    #2
    1. Advertising

  3. JesterDev

    why? Guest

    On Thu, 15 Jan 2004 20:17:18 GMT, JesterDev wrote:

    >Would anyone happen to know of a program that will
    >take a directory listing on my hard drive, and convert
    >it to html?


    Dir2HTML
    http://www.pc-tools.net/win32/freeware/dir2html/

    <snip>

    Me
    why?, Jan 15, 2004
    #3
  4. JesterDev

    wisefool Guest

    JesterDev provided these words:
    > Would anyone happen to know of a program that will
    > take a directory listing on my hard drive, and convert
    > it to html?
    >
    > I could do this by hand, but I thought maybe there was
    > some software that might be able to do this.
    >
    > What I'm after is something that will just add links to
    > the various files not the directories themselves.. Like
    >
    > file1.bas - Links to file1.bas
    > file2.bas - links to file2.bas


    For vaguely interested propellor heads only:

    Should work on WinNT/2K/XP. (Tested on XP.)

    Save *between* hyphen lines as htmldir.bat and stick in Windows\system32
    directory:
    ------------------------------
    @echo off
    setlocal
    pushd
    if not "%1"=="" CD %1
    echo ^<HTML^>^<BODY^>
    echo ^<H1^>Directory listing of
    cd
    echo ^</H1^>
    for /D %%d in (*) do echo ^<A href='%%d'^>%%d ^</A^> ^&lt;DIR^&gt;^<BR^>
    for %%f in (*) do echo ^<A href='%%f'^>%%f^</A^>^<BR^>
    echo ^</BODY^>^</HTML^>
    popd
    ------------------------------

    To use at command line:

    htmldir [<dir-name>] [> <destination-file.html>]

    In the above:
    ^ escapes any of <>&|
    %%d is replaced with directory names
    and %%f is replaced with file names.

    wisefool
    wisefool, Jan 15, 2004
    #4
  5. JesterDev

    wisefool Guest

    JesterDev provided these words:
    > Would anyone happen to know of a program that will
    > take a directory listing on my hard drive, and convert
    > it to html?
    >
    > I could do this by hand, but I thought maybe there was
    > some software that might be able to do this.
    >
    > What I'm after is something that will just add links to
    > the various files not the directories themselves.. Like
    >
    > file1.bas - Links to file1.bas
    > file2.bas - links to file2.bas


    For die hard batch-script / console users only:

    Can generate HTML (including <> characters) from Windows
    NT/2K/XP command line something like this (shift lines after
    for statements onto end of previous lines,
    and save as <Windows>\htmldir.bat):
    ------------------------------
    @echo off
    setlocal
    pushd
    if not "%1"=="" CD %1
    echo ^<HTML^>^<BODY^>
    echo ^<H1^>Directory listing of
    cd
    echo ^</H1^>
    for /D %%d in (*) do
    echo ^<A href='%2%%d'^>%%d ^</A^> (dir)^<BR^>
    for %%f in (*) do
    echo ^<A href='%2%%f'^>%%f^</A^>^<BR^>
    echo ^</BODY^>^</HTML^>
    popd
    ------------------------------

    To use at command line:
    htmldir [<dir-list-name>] [link-prefix] [> <destination-file.html>]

    e.g. To list current directory in HTML format:
    C:\MYDIR> htmldir

    e.g. To create a listing of C:\ with links forced to start with "C:\" :
    C:\MYDIR> htmldir c:\ c:\ > index.html

    wisefool
    wisefool, Jan 15, 2004
    #5
  6. JesterDev

    wisefool Guest

    wisefool provided these words:
    > JesterDev provided these words:
    >> Would anyone happen to know of a program that will
    >> take a directory listing on my hard drive, and convert
    >> it to html?
    >>
    >> I could do this by hand, but I thought maybe there was
    >> some software that might be able to do this.
    >>
    >> What I'm after is something that will just add links to
    >> the various files not the directories themselves.. Like
    >>
    >> file1.bas - Links to file1.bas
    >> file2.bas - links to file2.bas

    >

    Last post slightly wrong in places. Use this post instead:

    For die hard batch-script / console users only:

    Can generate HTML (including <> characters) from Windows
    NT/2K/XP command line something like this (shift lines after
    for statements onto end of previous lines,
    and save as <Windows>\htmldir.bat [NOT in system32]):
    ------------------------------
    @echo off
    setlocal
    pushd
    if not "%1"=="" CD %1
    echo ^<HTML^>^<BODY^>
    echo ^<H1^>Directory listing of
    cd
    echo ^</H1^>
    for /D %%d in (*) do
    echo ^<A href='%2%%d'^>%%d ^</A^> (dir)^<BR^>
    for %%f in (*) do
    echo ^<A href='%2%%f'^>%%f^</A^>^<BR^>
    echo ^</BODY^>^</HTML^>
    popd
    ------------------------------

    To use at command line:
    htmldir [<dir-list-name>] [link-prefix] [> <destination-file.html>]

    e.g. To list current directory in HTML format:
    C:\MYDIR> htmldir

    e.g. To create a listing of C:\ with links forced to start with "C:\" :
    C:\MYDIR> htmldir c:\ c:\ > index.html

    wisefool
    wisefool, Jan 15, 2004
    #6
  7. JesterDev

    JesterDev Guest

    wisefool wrote:

    > JesterDev provided these words:
    >
    >>Would anyone happen to know of a program that will
    >>take a directory listing on my hard drive, and convert
    >>it to html?
    >>
    >>I could do this by hand, but I thought maybe there was
    >>some software that might be able to do this.
    >>
    >>What I'm after is something that will just add links to
    >>the various files not the directories themselves.. Like
    >>
    >>file1.bas - Links to file1.bas
    >>file2.bas - links to file2.bas

    >
    >
    > For vaguely interested propellor heads only:
    >
    > Should work on WinNT/2K/XP. (Tested on XP.)
    >
    > Save *between* hyphen lines as htmldir.bat and stick in Windows\system32
    > directory:
    > ------------------------------
    > @echo off
    > setlocal
    > pushd
    > if not "%1"=="" CD %1
    > echo ^<HTML^>^<BODY^>
    > echo ^<H1^>Directory listing of
    > cd
    > echo ^</H1^>
    > for /D %%d in (*) do echo ^<A href='%%d'^>%%d ^</A^> ^&lt;DIR^&gt;^<BR^>
    > for %%f in (*) do echo ^<A href='%%f'^>%%f^</A^>^<BR^>
    > echo ^</BODY^>^</HTML^>
    > popd
    > ------------------------------
    >
    > To use at command line:
    >
    > htmldir [<dir-name>] [> <destination-file.html>]
    >
    > In the above:
    > ^ escapes any of <>&|
    > %%d is replaced with directory names
    > and %%f is replaced with file names.
    >
    > wisefool
    >
    >

    Thanks a ton!
    JesterDev, Jan 15, 2004
    #7
  8. JesterDev

    wisefool Guest

    JesterDev provided these words:
    >



    Really? It was that good, splendid I am pleased. ;-)
    wisefool, Jan 16, 2004
    #8
  9. > Would anyone happen to know of a program that will
    > take a directory listing on my hard drive, and convert
    > it to html?



    Here is a small app that can do that...
    http://quantum.fateback.com/freeware/dir2html.htm


    --
    ----------------------------------------
    Quantum Illusions: http://quantum.2ya.com
    FORT Freeware: http://freeware.quantum.2ya.com
    Pegasus Mail Support Site: http://pegasus.quantum.2ya.com
    DATA Solutions: http://datasolutions.quantum.2ya.com

    If you truly want to contact me click the link
    http://quantum.2ya.com/email.htm
    Bebop & Rocksteady, Jan 16, 2004
    #9
  10. On Fri, 16 Jan 2004 00:56:09 -0000, "wisefool" <>
    wrote:

    >JesterDev provided these words:
    >>

    >
    >
    >Really? It was that good, splendid I am pleased. ;-)

    Well... The links didn't come out the way he wanted.... He wanted them
    to say <a href="file1.htm"> and you have <a
    href="file://c:\util\file1.htm"> ....
    John H. Guillory, Jan 18, 2004
    #10
  11. JesterDev

    wisefool Guest

    John H. Guillory said:
    > On Fri, 16 Jan 2004 00:56:09 -0000, "wisefool" <>
    > wrote:
    >
    >> JesterDev provided these words:
    >>>

    >>
    >>
    >> Really? It was that good, splendid I am pleased. ;-)

    > Well... The links didn't come out the way he wanted.... He wanted them
    > to say <a href="file1.htm"> and you have <a
    > href="file://c:\util\file1.htm"> ....


    Bebop & Rocksteady's suggestion looks cooler than my script? (Though
    I haven't downloaded and taken a look. Otherwise,

    This was the recomended version: news:bu725d$sur$
    It is bare bones and works on at least XP Home SP2 and NT 4.0 Wkstation SP6.
    If you want recursion into subdirectories or different features, use another
    product! ;-)
    I have not tested it on other OSes. Maybe it does weird things on 2K.
    I don't know how you're getting a link prefix like file://c:\util unless
    either this
    happens when you use 2K due to OS differences or you are specifying this
    link
    prefix - the prefix is an optional argument.
    If you don't want sub-DIRs listed, remove the "for /D" line.
    I wouldn't know whether this would work on 95/98/ME. It might.

    wisefool
    wisefool, Jan 18, 2004
    #11
  12. On Sun, 18 Jan 2004 03:31:19 -0000, "wisefool" <>
    wrote:

    >Bebop & Rocksteady's suggestion looks cooler than my script? (Though
    >I haven't downloaded and taken a look. Otherwise,

    I've seen a VB Program that would do awesomely if it wouldn't be for
    the fact that you can't make it command-line driven.... Personally, I
    love your script, just wished I could strip the path names out of
    it.... Like he said in the original post.... The way yours does it is
    to point to a local file on the hard drive, to quickly place files on
    a web server, it'd be easier to have the name only, put the .html file
    in that directory, and link that directory as a sub-directory on the
    server.... But your script could be used in conjunction with a
    seperate program that went through and parsed out the pathnames...
    That'd be an option.... I'm presently thinking about writing my own
    program to do similiar, but I'd prefer the batch file method, because
    it'd be much simplier to customize.... For starters, I'd like to have
    a table created with the filename (and a link to the file) in the
    first column, the second column is the file size, and perhaps a 3rd
    column for either a preview of the picture if its a picture file or a
    short description of the type of file, eg. (ZIP file, DLL File,
    Executable, etc,,,,)
    John H. Guillory, Jan 19, 2004
    #12
  13. JesterDev

    wisefool Guest

    John H. Guillory said:
    > On Sun, 18 Jan 2004 03:31:19 -0000, "wisefool" <>
    > wrote:
    >
    >> Bebop & Rocksteady's suggestion looks cooler than my script? (Though
    >> I haven't downloaded and taken a look. Otherwise,

    > I've seen a VB Program that would do awesomely if it wouldn't be for
    > the fact that you can't make it command-line driven.... Personally, I
    > love your script, just wished I could strip the path names out of
    > it.... Like he said in the original post.... The way yours does it is
    > to point to a local file on the hard drive, to quickly place files on
    > a web server, it'd be easier to have the name only, put the .html file
    > in that directory, and link that directory as a sub-directory on the
    > server.... But your script could be used in conjunction with a
    > seperate program that went through and parsed out the pathnames...
    > That'd be an option.... I'm presently thinking about writing my own
    > program to do similiar, but I'd prefer the batch file method, because
    > it'd be much simplier to customize.... For starters, I'd like to have
    > a table created with the filename (and a link to the file) in the
    > first column, the second column is the file size, and perhaps a 3rd
    > column for either a preview of the picture if its a picture file or a
    > short description of the type of file, eg. (ZIP file, DLL File,
    > Executable, etc,,,,)


    This should keep me amused for a while. I am still mystified as to why
    you are getting path names. Here's what I'm seeing on *Windows
    XP Home*:

    C:\>md b

    C:\>copy con: c:\b\fish
    hello
    ^Z
    1 file(s) copied.

    C:\>htmldir c:\b
    <HTML><BODY>
    <H1>Directory listing of
    C:\b
    </H1>
    <A href='fish'>fish</A><BR>
    </BODY></HTML>

    C:\>

    I see no paths being generated. What OS are you using?

    I am now looking at writing a .JS (JScript) version of my
    script using Windows Scripting, inspecting directories
    and files using a "scripting object". This should be more
    cross-platform compatible, and won't be much bigger.

    Again the expectation would be that users would edit the
    script to put in their own formatting, like you say for
    example tables.

    I expect to post it within a day.

    wisefool
    wisefool, Jan 19, 2004
    #13
  14. JesterDev

    wisefool Guest

    John H. Guillory said:
    > On Sun, 18 Jan 2004 03:31:19 -0000, "wisefool" <>
    > wrote:
    >
    >> Bebop & Rocksteady's suggestion looks cooler than my script? (Though
    >> I haven't downloaded and taken a look. Otherwise,

    > I've seen a VB Program that would do awesomely if it wouldn't be for
    > the fact that you can't make it command-line driven.... Personally, I
    > love your script, just wished I could strip the path names out of
    > it.... Like he said in the original post.... The way yours does it is
    > to point to a local file on the hard drive, to quickly place files on
    > a web server, it'd be easier to have the name only, put the .html file
    > in that directory, and link that directory as a sub-directory on the
    > server.... But your script could be used in conjunction with a
    > seperate program that went through and parsed out the pathnames...
    > That'd be an option.... I'm presently thinking about writing my own
    > program to do similiar, but I'd prefer the batch file method, because
    > it'd be much simplier to customize.... For starters, I'd like to have
    > a table created with the filename (and a link to the file) in the
    > first column, the second column is the file size, and perhaps a 3rd
    > column for either a preview of the picture if its a picture file or a
    > short description of the type of file, eg. (ZIP file, DLL File,
    > Executable, etc,,,,)


    Web servers do this automatically, don't they? What
    is the reasoning behind using a command-line tool to generate
    index pages for web servers? I assumed this tool was
    for use when browsing local file systems. What is the thinking
    here?

    wisefool
    wisefool, Jan 19, 2004
    #14
  15. JesterDev

    wisefool Guest

    John H. Guillory said:
    > On Sun, 18 Jan 2004 03:31:19 -0000, "wisefool" <>
    > wrote:
    >
    >> Bebop & Rocksteady's suggestion looks cooler than my script? (Though
    >> I haven't downloaded and taken a look. Otherwise,

    > I've seen a VB Program that would do awesomely if it wouldn't be for
    > the fact that you can't make it command-line driven....

    No reason in principle why VB apps can't be driven from the command
    line.

    wisefool
    wisefool, Jan 19, 2004
    #15
  16. On Mon, 19 Jan 2004 05:17:49 -0000, "wisefool" <>
    wrote:

    >This should keep me amused for a while. I am still mystified as to why
    >you are getting path names. Here's what I'm seeing on *Windows
    >XP Home*:
    >
    >C:\>md b
    >
    >C:\>copy con: c:\b\fish
    >hello
    >^Z
    > 1 file(s) copied.

    Sorry, My mistake, I found what happened.... I viewed the .html file
    and found out I was really seeing the same thing as you where seeing,
    but when I viewed the .html file in Internet explorer to see how it
    looked, it was showing file://c:/util/pk250dos.exe eg. as the URL
    (not thinking that it only showed the name of the file on the page
    its self....) What's weird is that even though the source shows
    http:// IE converts it to a file:// because its local... Cool,
    making a table out of it and adding color is simple....
    John H. Guillory, Jan 19, 2004
    #16
  17. On Mon, 19 Jan 2004 05:31:29 -0000, "wisefool" <>
    wrote:

    >Web servers do this automatically, don't they? What
    >is the reasoning behind using a command-line tool to generate
    >index pages for web servers? I assumed this tool was
    >for use when browsing local file systems. What is the thinking
    >here?


    1> Not all webservers do this automatically
    2> You don't necessarily want it done fully automatic.... Suppose you
    have a directory of files you download into in your web server. You
    want to check those files out and make sure you don't need to delete
    any files before making them available to the public. You check all
    the files out, run the program to make the index file, then the user
    sees only what that .html file shows them. letting the web server
    generate an index file for you is considered a very big risk!
    John H. Guillory, Jan 19, 2004
    #17
  18. 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....
    John H. Guillory, Jan 19, 2004
    #18
  19. JesterDev

    wisefool Guest

    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,subpathadd1,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
    wisefool, Jan 20, 2004
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    4
    Views:
    9,096
    flashDuniya
    Jan 7, 2009
  2. Ed Mullen

    Changing dir for tmp files

    Ed Mullen, Mar 6, 2004, in forum: Firefox
    Replies:
    0
    Views:
    511
    Ed Mullen
    Mar 6, 2004
  3. H.C.Vink
    Replies:
    1
    Views:
    533
    Walter Roberson
    Jul 24, 2003
  4. wisefool

    Re: Dir listing to html?

    wisefool, Jan 20, 2004, in forum: Computer Support
    Replies:
    2
    Views:
    902
    wisefool
    Jan 20, 2004
  5. Monima
    Replies:
    0
    Views:
    1,751
    Monima
    Dec 14, 2010
Loading...

Share This Page