Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2007
    Posts
    33

    Unanswered: File System Object - Combine 3 files into 1

    I have an export file that updates each night and dumps into prices.txt

    I have to send them to an ftp site that processes them automatically if they're formatted correctly. They contain the same header information (saved in header.txt) and footer information (saved in footer.text). I then combine them all
    header.txt + prices.txt + footer.txt = glpcwholesale.prn

    The script below is what I have so far but it isn't working and errors out on line 23.

    Any help would be great.

    Code:
    Function Main()
    
    ' OpenTextFile Method needs a Const value
    ' ForAppending = 8 ForReading = 1, ForWriting = 2
    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8
    
    ' Create the File System Object
    Dim objFSO1, objFSO2,objFSO3,objFSO4
    
    Set objFSO1 = CreateObject("Scripting.FileSystemObject")
    Set objFSO2 = CreateObject("Scripting.FileSystemObject")
    Set objFSO3 = CreateObject("Scripting.FileSystemObject")
    Set objFSO4 = CreateObject("Scripting.FileSystemObject")
    
    'Creating string references to file locations
    Dim strDirectory, strFileHeader, strFilePrices, strFileTrailer
    Dim strFileGLPC
    
    strDirectory = "C:\Data\GarrowPRN"
    strFileHeader = "\header.txt"
    strFileTrailer="\trailer.txt"
    strFilePrices="\prices.txt"
    
    strFileGLPC='\glpcwholesale.prn"
    
    'Creating File Objects Text File Reference
    Dim objFileHeader, objFilePrices, objFileTrailer, objFileGLPCWholesale
    
    Set objFileHeader = objFSO1.OpenTextFile _
    (strDirectory & strFileHeader, ForReading, True)
    Set objFilePrices = objFSO2.OpenTextFile _
    (strDirectory & strFileTrailer, ForReading, True)
    Set objFileTrailer = objFSO3.OpenTextFile _
    (strDirectory & strFilePrices, ForReading, True)
    Set objFileGLPCWholesale = objFSO4.OpenTextFile _
    (strDirectory &strFileGLPC, ForWriting, True)
    
    Do While (objFileHeader.AtEndOfStream <>
    True) 
    
    objFileGLPCWholesale.WriteLine(objFileHeader.ReadLine)
    
    loop
    objFileGLPCWholesale.Close
    Set objFileGLPCWholesale = objFSO4.OpenTextFile _
    (strDirectory &strFileGLPC, ForAppend, True)
    
    Do While (objFilePrices.AtEndOfStream <>
    True) 
    
    objFileGLPCWholesale.WriteLine(objFilePrices.ReadLine)
    
    loop
    Do While (objFileTrailer.AtEndOfStream <>
    True) 
    
    objFileGLPCWholesale.WriteLine(objFileTrailer.ReadLine)
    
    loop
    
    objFileHeader.Close
    objFilePrices .Close
    objFileTrailer .Close
    objFileGLPCWholesale.Close
    
    SET objFileHeader = NOTHING
    SET objFilePrices = NOTHING
    SET objFileTrailer = NOTHING
    SET objFileGLPCWholesale = NOTHING
    
    	Main = DTSTaskExecResult_Success
    End Function

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    You put an apostrophe instead of a quote:

    strFileGLPC='\glpcwholesale.prn"
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Feb 2007
    Posts
    33

    Thanks Anything else

    I write SQL code mostly. Using ' around strings all the time becomes second nature after a while.

    Anyone else have trouble changing their typing mindset between programming languages. I've been working in SQL mostly and floating between crystal reports, asp.net(vb.net), and AJAX (javascript). Keeping up on all the little differences is a pain sometime.

    Is there a better way to develop active x controls for SQL 2000 DTS processes than in the DTS designer. It doesn't support intellitype. Its a pain to write code in unless you are really sure about what you're writing or really love debuging code all the time.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I kind of like Visual Studio for creating Active-X controls myself.

    -PatP

  5. #5
    Join Date
    Feb 2007
    Posts
    33

    Still having errors.

    Code Erroring out now on start of first do while loop. Like 39 it says syntax error.

    Code:
    Function Main()
    
    ' OpenTextFile Method needs a Const value
    ' ForAppending = 8 ForReading = 1, ForWriting = 2
    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8
    
    ' Create the File System Object
    Dim objFSO1, objFSO2,objFSO3,objFSO4
    
    Set objFSO1 = CreateObject("Scripting.FileSystemObject")
    Set objFSO2 = CreateObject("Scripting.FileSystemObject")
    Set objFSO3 = CreateObject("Scripting.FileSystemObject")
    Set objFSO4 = CreateObject("Scripting.FileSystemObject")
    
    'Creating string references to file locations
    Dim strDirectory, strFileHeader, strFilePrices, strFileTrailer
    Dim strFileGLPC
    
    strDirectory = "C:\Data\GarrowPRN"
    strFileHeader = "\header.txt"
    strFileTrailer="\trailer.txt"
    strFilePrices="\prices.txt"
    
    strFileGLPC="\glpcwholesale.prn"
    
    'Creating File Objects Text File Reference
    Dim objFileHeader, objFilePrices, objFileTrailer, objFileGLPCWholesale
    
    Set objFileHeader = objFSO1.OpenTextFile _
    (strDirectory & strFileHeader, ForReading, True)
    Set objFilePrices = objFSO2.OpenTextFile _
    (strDirectory & strFileTrailer, ForReading, True)
    Set objFileTrailer = objFSO3.OpenTextFile _
    (strDirectory & strFilePrices, ForReading, True)
    Set objFileGLPCWholesale = objFSO4.OpenTextFile _
    (strDirectory &strFileGLPC, ForWriting, True)
    
    Do While (objFileHeader.AtEndOfStream <>
    True) 
    
    objFileGLPCWholesale.WriteLine(objFileHeader.ReadLine)
    
    loop
    objFileGLPCWholesale.Close
    Set objFileGLPCWholesale = objFSO4.OpenTextFile _
    (strDirectory &strFileGLPC, ForAppend, True)
    
    Do While (objFilePrices.AtEndOfStream <>
    True) 
    
    objFileGLPCWholesale.WriteLine(objFilePrices.ReadLine)
    
    loop
    Do While (objFileTrailer.AtEndOfStream <>
    True) 
    
    objFileGLPCWholesale.WriteLine(objFileTrailer.ReadLine)
    
    loop
    
    objFileHeader.Close
    objFilePrices .Close
    objFileTrailer .Close
    objFileGLPCWholesale.Close
    
    SET objFileHeader = NOTHING
    SET objFilePrices = NOTHING
    SET objFileTrailer = NOTHING
    SET objFileGLPCWholesale = NOTHING
    
    	Main = DTSTaskExecResult_Success
    End Function

  6. #6
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Do you know how to debug VBS scripts?
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  7. #7
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    From O/S

    type file.txt > newfile.txt
    type file2.txt | find /V "header text" >> newfile.txt
    type file3.txt | find /V "header text" >> newfile.txt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •