![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VBscribt to read CSV file and creat other file Hi All I want VBScribt that read spesifc coulm in CSV file and write iy in new CSV file |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBscribt to read CSV file and creat other file In article <DE04C144-0D5F-445E-BFF2-19244A589688@xxxxxx>, MK@xxxxxx says... Quote: > Hi All > > I want VBScribt that read spesifc coulm in CSV file and write iy in new CSV > file line from the original file, parse it out to find the column you want, and then write it out again. -- /~\ The ASCII \ / Ribbon Campaign X Against HTML / \ Email! Remove the ns_ from if replying by e-mail (but keep posts in the newsgroups if possible). |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VBscribt to read CSV file and creat other file "M.K" <MK@xxxxxx> wrote in message news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxxQuote: > Hi All > > I want VBScribt that read spesifc coulm in CSV file and write iy in new > CSV > file > csv file linked here: http://www.rlmueller.net/ReadCSV.htm The function parses each line and puts the values into an array. For example, to output the values in the third field of the csv file, the program can be similar to below: ============ Option Explicit Dim objFSO, strInput, objInput Dim arrValues, strItem, strLine Dim strOutput, objOutput Const ForReading = 1 Const ForWriting = 2 ' Specify the csv file. strInput = "c:\Scripts\Test.csv" ' Specify the new file. strOutput = "c:\Scripts\Output.csv" ' Open the input file for read access Set objFSO = CreateObject("Scripting.FileSystemObject") Set objInput = objFSO.OpenTextFile(strInput, ForReading) ' Open the output file for writing. Set objOutput = objFSO.OpenTextFile(strOutput, ForWriting) ' Read the file. Do Until objInput.AtEndOfStream strLine = objInput.ReadLine ' Skip blank lines. If (Trim(strLine) <> "") Then ' Parse the fields in the file. arrValues = CSVParse(strLine) ' Write the value in the third field to the output file. objOutput.WriteLine arrValues(2) End If Loop ' Clean up. objInput.Close objOutput.Close ======== Note that arrays a zero based. That is, the first field in arrValues is arrValues(0). The third field is arrValues(2). You must include the Function CSVParse from the link I gave earlier. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: VBscribt to read CSV file and creat other file "M.K" <MK@xxxxxx> wrote in message news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxxQuote: > Hi All > > I want VBScribt that read spesifc coulm in CSV file and write iy in new > CSV > file Heading1,Heading2,Heading3,Heading4 Value1-1,Value1-2,Value1-3,Value1-4 Value2-1,Value2-2,Value2-3,Value2-4 Value3-1,Value3-2,Value3-3,Value3-4 Are you wanting to specify a column, let's say 'Heading2' and have it output like below to another file? Heading2 Value1-2 Value2-2 Value3-2 |
My System Specs![]() |
| | #5 (permalink) |
| | Re: VBscribt to read CSV file and creat other file Hi James Whitlow, Thank you for replay Yes that what i want, I want the following reult in new csv file Heading2 Value1-2 Value2-2 Value3-2 "James Whitlow" wrote: Quote: > "M.K" <MK@xxxxxx> wrote in message > news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxxQuote: > > Hi All > > > > I want VBScribt that read spesifc coulm in CSV file and write iy in new > > CSV > > file > Help me understand, please. If you have a CSV like: > > Heading1,Heading2,Heading3,Heading4 > Value1-1,Value1-2,Value1-3,Value1-4 > Value2-1,Value2-2,Value2-3,Value2-4 > Value3-1,Value3-2,Value3-3,Value3-4 > > Are you wanting to specify a column, let's say 'Heading2' and have it > output like below to another file? > > Heading2 > Value1-2 > Value2-2 > Value3-2 > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: VBscribt to read CSV file and creat other file "M.K" <MK@xxxxxx> wrote in message news:81535E40-4DD4-4B00-B7AD-9C416BBFCE10@xxxxxx Quote: > Hi James Whitlow, > > > Thank you for replay > > Yes that what i want, I want the following reult in new csv file > > Heading2 > Value1-2 > Value2-2 > Value3-2 > > > > > > "James Whitlow" wrote: > Quote: >> "M.K" <MK@xxxxxx> wrote in message >> news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxxQuote: >> > Hi All >> > >> > I want VBScribt that read spesifc coulm in CSV file and write iy in new >> > CSV >> > file >> Help me understand, please. If you have a CSV like: >> >> Heading1,Heading2,Heading3,Heading4 >> Value1-1,Value1-2,Value1-3,Value1-4 >> Value2-1,Value2-2,Value2-3,Value2-4 >> Value3-1,Value3-2,Value3-3,Value3-4 >> >> Are you wanting to specify a column, let's say 'Heading2' and have it >> output like below to another file? >> >> Heading2 >> Value1-2 >> Value2-2 >> Value3-2 >> >> >> However, if the values should be enclosed in quotes, you can replace this statement: objOutput.WriteLine arrValues(2) with this: objOutput.WriteLine """" & arrValues(2) & """" Note that this writes a string to the file that is the concatenation of three strings. The string """" resolves to a single quote character. Strings are enclosed in quotes and any embedded quote characters in the string must be doubled. The values must be enclosed in quotes if the have embedded commas. The function CSVParse handles the csv file properly whether the values are quoted or not (as long as values with commas are quoted). -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #7 (permalink) |
| | Re: VBscribt to read CSV file and creat other file > "James Whitlow" wrote: Quote: > Quote: >> "M.K" <MK@xxxxxx> wrote in message >> news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxxQuote: >> > Hi All >> > >> > I want VBScribt that read spesifc coulm in CSV file and write iy in new >> > CSV >> > file >> Help me understand, please. If you have a CSV like: >> >> Heading1,Heading2,Heading3,Heading4 >> Value1-1,Value1-2,Value1-3,Value1-4 >> Value2-1,Value2-2,Value2-3,Value2-4 >> Value3-1,Value3-2,Value3-3,Value3-4 >> >> Are you wanting to specify a column, let's say 'Heading2' and have it >> output like below to another file? >> >> Heading2 >> Value1-2 >> Value2-2 >> Value3-2 >> >> >>"M.K" <MK@xxxxxx> wrote in message >>news:81535E40-4DD4-4B00-B7AD-9C416BBFCE10@xxxxxx > > > Thank you for replay > > Yes that what i want, I want the following reult in new csv file > > Heading2 > Value1-2 > Value2-2 > Value3-2 Dim oFSO, oDB, oRS, sOldFile, sNewFile, sColumn, sSource sOldFile = "C:\My File.csv" sNewFile = "C:\New File.txt" sColumn="Heading2" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oDB = CreateObject("ADODB.Connection") sSource = oFSO.GetParentFolderName(sOldFile) sOldFile = oFSO.GetFileName(sOldFile) oDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sSource _ & ";Extended Properties=""text;HDR=YES;FMT=Delimited""" Set oRS = oDB.Execute("SELECT * FROM [" & sOldFile & "]") With oFSO.OpenTextFile(sNewFile, 2, True) .WriteLine sColumn Do Until oRS.EOF .WriteLine oRS.Fields(sColumn) oRS.MoveNext Loop End With |
My System Specs![]() |
| | #8 (permalink) |
| | Re: VBscribt to read CSV file and creat other file "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:eNVMpHwCKHA.528@xxxxxx Quote: Quote: >> "James Whitlow" wrote: >> Quote: >>> "M.K" <MK@xxxxxx> wrote in message >>> news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxx>>> > Hi All >>> > >>> > I want VBScribt that read spesifc coulm in CSV file and write iy in >>> > new >>> > CSV >>> > file >>> >>> Help me understand, please. If you have a CSV like: >>> >>> Heading1,Heading2,Heading3,Heading4 >>> Value1-1,Value1-2,Value1-3,Value1-4 >>> Value2-1,Value2-2,Value2-3,Value2-4 >>> Value3-1,Value3-2,Value3-3,Value3-4 >>> >>> Are you wanting to specify a column, let's say 'Heading2' and have it >>> output like below to another file? >>> >>> Heading2 >>> Value1-2 >>> Value2-2 >>> Value3-2 >>> >>> >>>"M.K" <MK@xxxxxx> wrote in message >>>news:81535E40-4DD4-4B00-B7AD-9C416BBFCE10@xxxxxx >> >> >> Thank you for replay >> >> Yes that what i want, I want the following reult in new csv file >> >> Heading2 >> Value1-2 >> Value2-2 >> Value3-2 > Ok, below is my suggested code. > > Dim oFSO, oDB, oRS, sOldFile, sNewFile, sColumn, sSource > > sOldFile = "C:\My File.csv" > sNewFile = "C:\New File.txt" > sColumn="Heading2" > > Set oFSO = CreateObject("Scripting.FileSystemObject") > Set oDB = CreateObject("ADODB.Connection") > > sSource = oFSO.GetParentFolderName(sOldFile) > sOldFile = oFSO.GetFileName(sOldFile) > > oDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sSource _ > & ";Extended Properties=""text;HDR=YES;FMT=Delimited""" > > Set oRS = oDB.Execute("SELECT * FROM [" & sOldFile & "]") > > With oFSO.OpenTextFile(sNewFile, 2, True) > .WriteLine sColumn > Do Until oRS.EOF > .WriteLine oRS.Fields(sColumn) > oRS.MoveNext > Loop > End With > handles comma delimited files well. More work is required to do the same thing in VBScript. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #9 (permalink) |
| | Re: VBscribt to read CSV file and creat other file "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:u$XA2fxCKHA.4168@xxxxxx Quote: > > "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message > news:eNVMpHwCKHA.528@xxxxxx Quote: Quote: >>> "James Whitlow" wrote: >>> >>>> "M.K" <MK@xxxxxx> wrote in message >>>> news E04C144-0D5F-445E-BFF2-19244A589688@xxxxxx>>>> > Hi All >>>> > >>>> > I want VBScribt that read spesifc coulm in CSV file and write iy in >>>> > new >>>> > CSV >>>> > file >>>> >>>> Help me understand, please. If you have a CSV like: >>>> >>>> Heading1,Heading2,Heading3,Heading4 >>>> Value1-1,Value1-2,Value1-3,Value1-4 >>>> Value2-1,Value2-2,Value2-3,Value2-4 >>>> Value3-1,Value3-2,Value3-3,Value3-4 >>>> >>>> Are you wanting to specify a column, let's say 'Heading2' and have it >>>> output like below to another file? >>>> >>>> Heading2 >>>> Value1-2 >>>> Value2-2 >>>> Value3-2 >>>> >>>> >>>>"M.K" <MK@xxxxxx> wrote in message >>>>news:81535E40-4DD4-4B00-B7AD-9C416BBFCE10@xxxxxx >>> Hi James Whitlow, >>> >>> >>> Thank you for replay >>> >>> Yes that what i want, I want the following reult in new csv file >>> >>> Heading2 >>> Value1-2 >>> Value2-2 >>> Value3-2 >> Ok, below is my suggested code. >> >> Dim oFSO, oDB, oRS, sOldFile, sNewFile, sColumn, sSource >> >> sOldFile = "C:\My File.csv" >> sNewFile = "C:\New File.txt" >> sColumn="Heading2" >> >> Set oFSO = CreateObject("Scripting.FileSystemObject") >> Set oDB = CreateObject("ADODB.Connection") >> >> sSource = oFSO.GetParentFolderName(sOldFile) >> sOldFile = oFSO.GetFileName(sOldFile) >> >> oDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sSource _ >> & ";Extended Properties=""text;HDR=YES;FMT=Delimited""" >> >> Set oRS = oDB.Execute("SELECT * FROM [" & sOldFile & "]") >> >> With oFSO.OpenTextFile(sNewFile, 2, True) >> .WriteLine sColumn >> Do Until oRS.EOF >> .WriteLine oRS.Fields(sColumn) >> oRS.MoveNext >> Loop >> End With >> > An excellent solution. The Jet driver should be on almost any client and > handles comma delimited files well. More work is required to do the same > thing in VBScript. sometime back from an old Usenet by you! |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can not Creat work file,check temp environment variable | Microsoft Office | |||
| Read a line from a text file, without loading the entire file inmemory | PowerShell | |||
| How do I read a VHD file | Vista General | |||
| can not read a file | Vista General | |||
| coping file from a remote file share - FILE IS NO LONG THERE bogus error message | Vista networking & sharing | |||