Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
File Conversion: unix to dos/dos to unix
Author:
Gareth Lapworth
E-mail:
Click to e-mail author
Submitted:
8/4/2004
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
40117
Simple procedure to convert textfiles from a unix format (line breaks with chr(10)) to dos format (line breaks with chr(13)) and vice versa.
Declarations:
Public Enum ConvertType dos2unix = 0 unix2dos = 1 End Enum
Code:
Public Function ConvertFile(OriginalFile As String, NewFile As String, eConvertType As ConvertType, _ Optional DeleteOriginal As Boolean = False) Dim OpenFileNum, SaveFileNum As Integer Dim NewFileBuffer As String ' We accept data only from ' This function will open a file and convert it to ' a txt file format usable under *nix or dos On Error GoTo Error_Found OpenFileNum = FreeFile ' grab the first free file Open OriginalFile For Input As #OpenFileNum ' open the unix file SaveFileNum = FreeFile ' get another free file to write to Open NewFile For Binary As #SaveFileNum ' open/create the save file Do While Not EOF(OpenFileNum) Line Input #OpenFileNum, NewFileBuffer ' retrive the text (if a unix file, then the entire text is on one line) If eConvertType = dos2unix Then ' Check what type of conversion to do NewFileBuffer = NewFileBuffer & Chr(10) Else NewFileBuffer = Replace(NewFileBuffer, Chr(10), vbCrLf) End If Put #SaveFileNum, , NewFileBuffer ' write out the file Loop Close #SaveFileNum Close #OpenFileNum If DeleteOriginal = True Then Kill OriginalFile Exit_Sub: Exit Function Error_Found: MsgBox "Error: " & Err.Description & vbCrLf & "Number: " & Err.Number Exit Function End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement