Doubling of file size with no change in content?!

Results 1 to 2 of 2

Thread: Doubling of file size with no change in content?!

  1. #1
    Monsur Hossain Guest

    Default Doubling of file size with no change in content?!

    &nbsp;<BR>This one has me stumped. As an experiment, I&#039;m splitting a file line by line, and then joining it again using vbNewLine. The interesting thing is, the file created by joining is double the size of the original file. When I open both files in notepad, they look exactly the same. I understand that when splitting the original file, I&#039;m not removing the ending vbNewLine, so there&#039;s a possibility the new file has two vbNewLines at the end of it. But this doesn&#039;t make sense because: a) there aren&#039;t extra lines between the lines in the new file and b) an extra vbNewLine wouldn&#039;t explain a doubling of file size. So my question is, where is all that extra size coming from? The code I used is pasted below. Thanks in advance.<BR><BR>monsur<BR><BR>< BR><BR>=========================================== ===================<BR><BR>Option Explicit<BR><BR>&#039; Define some variables<BR>const ForReading = 1, ForWriting = 2<BR>Dim InputFSO, InputTSO<BR>Dim InputArray()<BR>Redim InputArray(-1)<BR>Dim OutputFSO, OutputTSO<BR>Dim OutputArray()<BR>ReDim OutputArray(i)<BR>Dim i<BR>Dim sFilename<BR>Dim sWriteBuffer<BR><BR>sFilename = "c: est.txt"<BR><BR>&#039; Open the test file<BR>Set InputFSO = CreateObject("Scripting.FileSystemObject")<BR>Set InputTSO = InputFSO.OpenTextFile("c: est.txt", ForReading)<BR><BR>&#039; assign each line of the test file to an element of an array.<BR>&#039; see<BR>&#039; for an explanation of why I do it this way.<BR>i = 0<BR>do until InputTSO.AtEndOfStream<BR> redim preserve InputArray(i)<BR> InputArray(i) = InputTSO.ReadLine<BR> i = i + 1<BR>loop<BR><BR>InputTSO.Close<BR>Set InputTSO = Nothing<BR>Set InputFSO = Nothing<BR><BR>&#039; Assign each element of the input array to the output array<BR>For i = 0 To UBound(InputArray)<BR> OutputArray(i) = InputArray(i)<BR>Next<BR><BR>&#039; Join each line of the array with a new line <BR>sWriteBuffer = join(OutputArray, vbNewLine)<BR><BR>&#039; Write the new text back to a file<BR>Set OutputFSO = CreateObject("Scripting.FileSystemObject")<BR>Set OutputTSO = OutputFSO.CreateTextFile("c: est2.txt", ForWriting, True)<BR>OutputTSO.Write sWriteBuffer <BR>OutputTSO.Close<BR><BR>Set OutputTSO = Nothing<BR>Set OutputFSO = Nothing<BR><BR>&#039; Now test2.txt will be about double the size of test.txt<BR>&#039; WHY????<BR><BR>=================================== ============================

  2. #2
    Join Date
    Dec 1969

    Default You *asked* it to!

    You wrote:<BR>&nbsp; &nbsp; Set OutputTSO = OutputFSO.CreateTextFile("c: est2.txt", ForWriting, True) <BR><BR>The last argument there, that you set to True, tells the system to create a UNICODE file. And unicode characters are *always* two bytes per character. So you got what you asked for.<BR><BR>

Posting Permissions

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