Click to See Complete Forum and Search --> : Convert UNIX to DOS file


quebecBoy
July 30th, 2001, 06:29 AM
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

Iouri
July 30th, 2001, 08:38 AM
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
iouri@hotsheet.com

Dark Sean
July 30th, 2001, 09:17 AM
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.

quebecBoy
July 30th, 2001, 09:46 AM
Thnaks!