Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Convert Linux files to Windows

  1. #1
    Board Regular
    Join Date
    Jan 2005
    Posts
    442
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Convert Linux files to Windows

    I received a bunch of text files from a Linux system. They have LF but no CR. When reading the file Excel VBA reads the entire file as one line.
    I write a little routine that makes the change. All the file names are in the array of strings.
    &&&&&&&&&&
    For file_number = 1 To FILE_NAME_COUNT
    input_file_name = DIR_NAME + file_names(file_number)
    Open input_file_name For Input As #2
    Line Input #2 , text
    read_length = Len(text)
    text = Replace(text, Chr(10), vbCrLf)
    Close #2
    Open input_file_name For Output As #2
    Print #2 , text
    Close #2
    Next file_number
    &&&&&&&&&&

    Problem: The Print line prints only up to the first CR. What can I use to write the entire string?
    Thank you,
    Bryan Kelly

    We need to know what a dragon is
    before we study its anatomy.
    (Bryan Kelly, 2010)

  2. #2
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,300
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Convert Linux files to Windows

    Hi Bryan,
    Try this:
    Code:
      Dim FF As Integer, s As String
      For file_number = 1 To FILE_NAME_COUNT
        input_file_name = DIR_NAME & file_names(file_number)
        FF = FreeFile
        Open input_file_name For Binary Access Read Write As FF
        s = String(LOF(FF), " ")
        Get FF, , s
        If InStr(s, vbCrLf) = 0 Then
          s = Replace(s, vbLf, vbCrLf)
          Put FF, 1, s
        End If
        Close FF
      Next
    Regards,
    Last edited by ZVI; Dec 10th, 2017 at 04:50 PM.
    Vladimir Zakharov
    Microsoft MVP Excel

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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