'Name: Fred Coleman 'Email_Address: fredkc@local.net 'Branch: 'Script_Type: vbscript 'Comment: 'takes a drive/folder name from input and return an HTML file listing of contents 'Script: '************************************************************** '* Directory Listing Script to HTML '* From a Design by Richard Harrison - richard.harrison@oldham.ac.uk '* Code taken from Donovan Kuln & Dale Ross postings on the '* newsgroup microsoft.public.scripting.wsh as well as example '* code from microsofts samples '* '* Last Updated - Aug. 12, 1998 '* '* Note '* 1) Needs a blank file by the name of DirList.txt in c:\ '* This is becuase the script will error if it cannot '* find it first time around. I dont know enough about '* scripting to know why you have to do this. '* '* 2) Note #1 is no longer the case. The program prompts the '* user for a starting folder for the listing and then puts '* the dirlist.txt file in that folder. If it exists, its '* overwritten, if not, created. '* '* This code added by Fred Coleman fredkc@local.net '* '* Sep. 13, 1998 '* '* 3) This version called Dirlist_H2.vbs writes the dir list '* to an HTML file: Dirlist.htm in the chosen sub/folder. '* '* This code cobbled by Fred Coleman fredkc@local.net '* With apologies to Richard Harrison. '* Sep. 15, 1998 '* '************************************************************** Option Explicit ' Create the FileSystem Object dim oFileSys, fh1, fh2, fh3, fh4, fh5 dim Dir, filcnt Dim Wedone Dim strDirDoneTxt Dim strMsgTitle dim strInput, strRunit Dim IExec, strTarget ' Change this file name if you ' want to use a different one. strTarget = "\DirList.htm" strInput= InputBox("Please Enter a starting folder", "User Input","") dir = strInput Set oFileSys = CreateObject("Scripting.FileSystemObject") set fh1=oFileSys.createTextFile(strInput & strTarget) fh1.WriteLine("") fh1.WriteLine("Listing of: " & strInput & "") fh1.WriteLine("") fh1.WriteLine("
") fh1.WriteLine("") fh1.WriteLine("Directory Listing of: " & Dir) fh1.WriteLine("
") fh1.close strDirDoneTxt ="HTML Listing Finished" strMsgTitle = "HTML Directory Lister." 'kick start it! GetDir dir ' Remove next comment if you want an Alert Box when its finished. ' Wedone = MsgBox(strDirDoneTxt, vbOKOnly + vbInformation, strMsgTitle ) '---------------------- sub GetDir(dir) dim fh2,fh3,oFolder,oFolders,oFiles,item,Item2,dacolr set oFolder=oFileSys.GetFolder(dir) set oFolders=oFolder.SubFolders set oFiles=oFolder.Files ' get all sub-folders in this folder For each item in oFolders 'go to each one GetDir(item) Next set fh4=oFileSys.openTextFile(strInput & strTarget,8) fh4.WriteLine("
" & "" & ofolder & "
") fh4.close filcnt = filcnt +1 item2=0 For each item2 in oFiles set fh3=oFileSys.openTextFile(strInput & strTarget,8) if dacolr = 1 then fh3.writeline("") dacolr = 0 else fh3.writeline("") dacolr = 1 end if fh3.WriteLine(Dir & "\" & item2.Name & "
") fh3.close filcnt = filcnt +1 next end sub set fh5=oFileSys.openTextFile(strInput & strTarget,8) fh5.WriteLine("
" & filcnt-2 & " items in the folder " & strInput & " and its sub-folders.
") fh5.WriteLine("
Thanks Fred!
") fh5.WriteLine("") fh5.close ' This section opens the file in IE after were done. ' If you dont want that, comment out the next four lines. Set IExec = CreateObject("InternetExplorer.Application") strRunit = strInput & strTarget IExec.navigate strRunit IExec.visible=1