' NAME: NamesFromCol1.vbs ' ' AUTHOR: Alan dot Kaplan at VA dot gov ' DATE : 3/19/2010 ' ' COMMENT: Converts a comma delimted or tab file into a list of ' items in the first column ' '========================================================================== 'based loosely on FSOReadCSV.Vbs 'http://www.microsoft.com/technet/scriptcenter/guide/sas_log_ldpe.mspx?mfr=True Option Explicit Const ForReading = 1 Const ForAppend = 8 Dim wshShell Set wshShell = WScript.CreateObject("WScript.Shell") dim fso,appendout Set fso = CreateObject("Scripting.FileSystemObject") dim quote quote=chr(34) Dim strDelim, bCSV bCSV = True 'False is TAB delimited Dim strFile, message, i, iStart, retval Dim oFile, strOutFile, strLine Dim aTemp If WScript.Arguments.Count = 1 Then strFile = WScript.Arguments(0) Else strFile = InputBox("Drag a comma or tab delimited file onto this script or enter path here:","Path") End If If strFile = "" Then WScript.Quit If Not FSO.FileExists(strFile) Then MsgBox FSO.GetFileName(strfile) & " not found",vbCritical + vbokonly End If Set oFile = FSO.OpenTextFile(strFile, ForReading) Message = "Start at what line? " & vbNewLine & vbNewLine For i = 1 To 5 message = message & "Line " & i & vbtab & left(oFile.ReadLine,30) & VbCrLf Next If InStr(oFile.ReadLine,vbTab) Then bCSV = False iStart = InputBox (message,"Start Line",1) oFile.Close If iStart = "" Then WScript.Quit If bCSV Then message = "Confirm, comma delimited file? (If you choose NO, will read as TAB delimited)" Else message = "Confirm, TAB delimited file? (If you choose NO, will read as comma delimited)" End If retval = MsgBox (message,vbYesNoCancel,"Confirm Type") If retval = vbCancel Then WScript.Quit If retval = vbNo Then bCSV = Not bCSV If bCSV Then strDelim = "," Else strDelim = vbTab End If strOutFile = FSO.BuildPath(FSO.GetParentFolderName(strFile),FSO.GetBaseName(strFile)& "_Col1.txt") If fso.FileExists(strOutFile) Then fso.DeleteFile strOutFile,True Set appendout = fso.OpenTextFile(strOutFile, ForAppend, True) Set oFile = FSO.OpenTextFile(strFile, ForReading) For i = 1 To iStart -1 'WScript.Echo "skipping" oFile.SkipLine Next Do While not(oFile.AtEndOfStream) 'Optional -- strip double quotes strLine =replace(oFile.Readline,quote,"") If inStr(strLine, strDelim) Then aTemp = split(strLine, strDelim) WriteLog atemp(0) Else oFile.Skipline End If i = i + 1 Loop oFile.Close appendout.Close wshShell.Run("notepad.exe " & strOutFile) Sub WriteLog (message) AppendOut.WriteLine message End Sub