1925 PST | 22JAN'08 | Joe
This script is used to pull the comments out of any script created
using Joe's VBScript Template.
'#==============================================================================
'#==============================================================================
'# SCRIPT.........: getComments.vbs
'# AUTHOR.........: Joe Glessner
'# EMAIL..........: jglessner@gmail.com
'# VERSION........: 1.0
'# DATE...........: 29JAN06
'# COPYRIGHT......: 2006, Joe Glessner
'# LICENSE........: Freeware
'# REQUIREMENTS...:
'#
'# DESCRIPTION....: Creates a text file containing all of the comments from
'# any script that is dropped onto this file. For this to
'# work correctly, comment lines must start with a backtick
'# and hash('#).
'#
'# NOTES..........: The resulting text file will be created in the root of
'# the "C:" drive by default.
'#
'# CUSTOMIZE......: To change the directory where the resulting text file is
'# created, change the variable "strOutFol" on line 48 to the
'# folder where you want the output file saved.
'#==============================================================================
'# REVISED BY.....:
'# EMAIL..........:
'# REVISION DATE..:
'# REVISION NOTES.:
'#
'#==============================================================================
'#==============================================================================
'**Start Encode**
'#=============================================================================
'# START OF SCRIPT
'#=============================================================================
Option Explicit
'On Error Resume Next
'#--------------------------------------------------------------------------
'# Declare Constants
'#--------------------------------------------------------------------------
'#--------------------------------------------------------------------------
'# Declare Variables
'#--------------------------------------------------------------------------
Dim strOutFol:strOutFol = "C:\"
Dim objShell, strOutFile, arg, strInFile, filesys, strFile, strStep
Dim myArray, strFileName
'#--------------------------------------------------------------------------
'# Take the input file and create the comment file.
'#--------------------------------------------------------------------------
Set objShell = WScript.CreateObject("WScript.Shell")
For Each arg In WScript.Arguments
strInFile = arg
Set filesys = CreateObject("Scripting.FileSystemObject")
Set strFile = filesys.GetFile(arg)
strStep = strFile.Name
myArray = Split(strStep, ".")
strFileName = myArray(0)
strOutFile = strOutFol & "Comments_From_" & strFileName & ".txt"
getComments strInFile, strOutfile
Next
'#==============================================================================
'# Functions / Subroutines / Classes
'#==============================================================================
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: getComments(strIn, strOut)
'# PURPOSE........: Copies all lines starting with ('#) from the
'# specified script file, To the specified text
'# document.
'# ARGUMENTS......: strIn = The input file.
'# strOut = The output file.
'# EXAMPLE........: getComments "c:\script.vbs", "c:\comments.vbs"
'# REQUIREMENTS...: Must have read/write access to the directory
'# containing this script and the directory containing
'# the input file.
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub getComments(strIn, strOut)
Const ForReading = 1
Const ForWriting = 2
Dim objFSO, objScriptFile, objCommentFile, strCurrentLine, intIsComment
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objScriptFile = objFSO.OpenTextFile(strIn, ForReading)
Set objCommentFile = objFSO.OpenTextFile(strOut, ForWriting, True)
Do While objScriptFile.AtEndOfStream <> True
strCurrentLine = objScriptFile.ReadLine
intIsComment = InStr(1,strCurrentLine,"'#")
If intIsComment > 0 Then
objCommentFile.Write strCurrentLine & VbCrLf
End If
Loop
objScriptFile.Close
objCommentFile.Close
End Sub
'#==============================================================================
'# END
'#==============================================================================
I use this script in conjunction with my script Template to create
"psuedo-documentation" for my completed scripts. This allows me to
quickly determine what a given script will and will not do.
I also use the file headers to create an index that allows me to
quickly determine if I have a script that will fit a task, or if I
have a script that can be easily altered to meet the task, rather
than having to write one from scratch.