CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Location
    France
    Posts
    4

    Convert UNIX to DOS file

    Hi,

    I want to read an Input file that was generated from a UNIX system.

    This is my code :

    Open FicName for input as #1
    Line input #1, FLigne



    => FicName (the file) and FLigne (string to hold the line read)

    But when I read the first line of this file, I don't get only the first line and this give me a memory problem (too much information).

    I know this is caused because some document generated from UNIX system do not terminate each line with a carriage return and a linefeed...

    So I was wondering if anyone of you knows how to convert a UNIX file to a DOS format (with CR and LF...)??

    I am able to convert it with an application (Ultra Edit) but I need to be able to do it in my application.

    thanks a lot, really appreciate it!

    Al


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Convert UNIX to DOS file

    Private Function convertDOStoUNIX(DOSstring As String) As String
    convertDOStoUNIX = Replace(DOSstring, vbCrLf, vbLf, 1, Len(DOSstring), vbTextCompare)
    End Function


    Private Function convertUNIXtoDOS(UNIXstring As String) As String
    convertUNIXtoDOS = Replace(UNIXstring, vbLf, vbCrLf, 1, Len(UNIXstring), vbTextCompare)
    End Function



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Feb 2000
    Posts
    149

    Re: Convert UNIX to DOS file

    I don't think it's necessary to do the conversion at all. A UNIX file should have a line feed, if you use the FileSystemObject and the ReadLine method it will only pick up one line.

    Set a reference to Microsoft Scripting Runtime.

    Code would look like this:



    Dim FSO as new FileSystemObject
    Dim fsoStream as TextStream
    Dim strLine as string

    set fsoStream = FSO.OpenTextFile(YourFileName with full path here)

    Do Until fsoStream.AtEndOfFile = true
    strLine = fsoStream.ReadLine
    Loop

    fsoStream.Close

    set FSO = nothing






    That should do it.




  4. #4
    Join Date
    Jul 2001
    Location
    France
    Posts
    4

    Re: Convert UNIX to DOS file

    Thnaks!


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured