View folder contents in a browser

Author Message
Silvertrout

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 11/23/2009
  • Status: offline
View folder contents in a browser Monday, November 23, 2009 4:45 PM (permalink)
0
Save the following script in the SendTo special folder, as perhaps 'View this folder contents in a browser.vbs', then right-click on a folder in Windows Explorer, select 'Send To', and drop it to the newly saved script....
 
Option Explicit
'
' Script to be used in the Sendto special folder, to generate a DIR listing
' of current folder, including all the subsequent sub-folders, to a HTML file. 
' Once generated, we will open it in a browser.
'
' Assumptions:
'   - HTML extension file is associated with a browser on the running PC.
'   - User has internet access (for the logo)
'     *Or you could reference a local file
'   - write access to the C:\ drive.
'     
'     
Dim fn, fn2, Drives(), i, x, y, outfn, fn2str
Dim objFSO, objShell, objTextFile, objFile, objArgs, objNetwork, colDrives
Dim strNextLine, strDirPre, strLink, strName, strImageFN
Dim arrayList(), ub
Const FORREADING = 1, FORWRITING = 2
' Location of the logo
strImageFN = "http://www.easternct.edu/career/images/magnifying-glass.gif"
Set objArgs = Wscript.Arguments
If Wscript.Arguments.Count = 0 Then
   fn = ""
Else
   fn = objArgs(0)
End If
If fn = "" Then
  Msgbox("Error: Expected a folder/directory name as the first argument..")
  WScript.Quit
End If
if mid(fn,2,2) <> ":\" then
   Msgbox("Error: :\ Is expected In " & fn)
   WScript.Quit
end if
fn2 = left(fn,2)
fn2str = ""
Set objNetwork = WScript.CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
   if colDrives.Item(i) = fn2 then
      fn2str = colDrives.Item (i + 1)
   End If
Next
Set objNetwork = Nothing
Const iNormalFocus = 1
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /C dir /S """ & fn & """ > c:\FolderList.txt"), iNormalFocus, True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\FolderList.txt", FORREADING)
i = 0
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    ReDim Preserve arrayList(i)
    arrayList(i) = strNextLine
    i = i + 1
Loop
objTextFile.Close
Set objFSO = Nothing
If UBound(arrayList) < 1 then
   Msgbox("Error: c:\FolderList.txt is empty??")
   Wscript.Quit
End If
outfn = "c:\FolderIndex.html"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(outfn, ForWriting, True)
objTextFile.WriteLine("<HTML><HEAD><TITLE>" & fn & "</TITLE></HEAD>")
objTextFile.WriteLine("  <BODY BGCOLOR=white TEXT=black>")
objTextFile.WriteLine("<img src=""" & strImageFN & """ width=""" & "100""" & _
                      " height=""" & "200""" & " alt=""" & "[Logo]""" & " border=""" & "0""" & ">")
objTextFile.WriteLine("<PRE>")
objTextFile.WriteLine("Contents of folder: '" & fn & "'")
If left(fn2str,2) = "\\" then
  objTextFile.WriteLine(" Absolute location: '" & fn2str & mid(fn,3) & "'")
Else
  objTextFile.WriteLine(" Absolute location: '" & fn & "'")
End If
objTextFile.WriteLine("             As at: " & time & " on: " & date)
objTextFile.WriteLine("**Note that directories are omitted from the list, only files are shown**")
objTextFile.WriteLine(" ")
objTextFile.WriteLine("To open a file, simply Click on it...")
For i = 1 To UBound(arrayList)
  If left(arrayList(i),10) = " Directory" Then
    objTextFile.WriteLine("")
    strDirPre = mid(arrayList(i),15,len(arrayList(i)))
    If left(fn2str,2) = "\\" then
      strDirPre = fn2str & mid(strDirPre,3)
    End If
    objTextFile.WriteLine(mid(arrayList(i),15,len(arrayList(i))))
  End If
  If mid(arrayList(i),3,1) = "/" Then
     If mid(arrayList(i),6,1) = "/" Then
        If mid(arrayList(i),15,1) = ":" Then
           If mid(arrayList(i),25,5) <> "<DIR>" Then
              strLink = "<A HREF=""" & strDirPre & "\"
             
              strName = mid(arrayList(i),40,len(arrayList(i)))
              objTextFile.WriteLine("  " & left(arrayList(i),38) & " " & strLink _
              & strName & """>" & strName & "</A>")
           End If
        End If
     End If
  End If
Next
objTextFile.WriteLine("</PRE></BODY></HTML>")
objTextFile.Close
Set objFSO = Nothing
objShell.Run outfn,iNormalFocus
Wscript.quit
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9