Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert space delimited file to comma delimited

Status
Not open for further replies.

RodP

Programmer
Jan 9, 2001
109
GB
Hi everyone,

I'd like some help in setting up a vbs file which works through a file of space delimited data, converts it to commas and then appends the data onto a master file. I'm not sure how to:

-Open the source file into memory and then go line by line
-replace a number of spaces with a comma for each line
-Append the edited lines (perhaps save the file first as a new file) to a master file (given that this file will steadily become larger and larger, ie. >64K and so can't really be put into a string).

I need to create this routine as a VBS so that I can call it up from windows schedular every 2 minutes or so.

The code I need to do this on is like the following:

2210 GrowcotC L:\GROUP\UBIMCASP.CHR
2210 GrowcotC L:\GROUP\UBIMCASP.HED
2210 GrowcotC L:\GROUP\UBIMCASP.IDX
2210 GrowcotC L:\GROUP\UBIMCASP.INF
2210 GrowcotC L:\GROUP\UBIMCASP.TAD
2040 WanigarD L:\GROUP\UBIMCBIS.CHR
2040 WanigarD L:\GROUP\UBIMCBIS.HED
2040 WanigarD L:\GROUP\UBIMCBIS.IDX
2040 WanigarD L:\GROUP\UBIMCBIS.INF
2040 WanigarD L:\GROUP\UBIMCBIS.TAD
223 RDCRP L:\GROUP\UBIMCCA1.CHR
223 RDCRP L:\GROUP\UBIMCCA1.HED
223 RDCRP L:\GROUP\UBIMCCA1.IDX

Thanks very much in advance

RodP
 
This isn't a line by line, but it should point you in the right direction.
Code:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile _
  ("C:\Temp\OriginalFile.txt", ForReading)
strOldFile = objFile.ReadAll
objInputFile.Close
Dim arrSplit()
arrSplit = Split(strOldFile, " ", -1, 1)
For Each strSplit in arrSplit
  If strSplit <> "" then _
    strNewFile = strNewFile+strSplit+","
Next
set objOutputFile = objFSO.CreateTextFile _
  "C:\Temp\NewFile.txt")
objOutputFile.WriteLine strUsr
objOutputFile.Close
I'm assuming you want the finished file to be in this format:
2210,GrowcotC,L:\GROUP\UBIMCASP.CHR

If you want each space to be a comma then remove this line:
If strSplit <> "" then _
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top