VB Script read txt

I have a need to open a txt file and then generate multiple files from it. this is a sample of what each line looks like, "31997869692",8/19/2011,"BAKR,CH R" the only thing that matters is the first number without the quotes. this number needs to be wrote to a file and then saved with the name being the number.RSD the extension has to be caps.

I do not know how to do this, I have an input box for the file name, that is about as far as I can get
dim strfile

  strfile = InputBox("Please enter file name", "File Info", ,100 ,200)
   WScript.Echo strfile

Open in new window

Who is Participating?
Bill PrewCommented:
Give this a try, I think it's close to what you described.

Const cForReading = 1
Const cForWriting = 2

sInFile = InputBox("Please enter file name", "File Info", ,100 ,200)
WScript.Echo sInFile

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oInFile = oFSO.OpenTextFile(sInFile, cForReading)

Do Until oInFile.AtEndOfStream
    sCurrentLine = oInFile.Readline
    aFields = Split(sCurrentLine , ",")
    sCurrentKey = aFields(0)
    sCurrentKey = Replace(sCurrentKey, """", "")
    Set oOutFile = oFSO.OpenTextFile(sCurrentKey & ".RSD", cForWriting, True)


Open in new window

Bill PrewCommented:
I'm a little confused, since the first number without quotes is a date, and repeats many times for the same value.  So you'd be writing the same file over and over, is that the intention?  Or if the field really the very first number on the line, like: 14997177449.RSD.

hoshie329Author Commented:
it is the second example 14997177449.RSD. Thank you
hoshie329Author Commented:
This works perfectly, great solution. Thanks
Bill PrewCommented:
Great, glad that worked out.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.