Converting CR to CR/LF

July 21st, 2005 - 05:42 am ET by Ralf Meuser | Report spam
Hi there


I'm a very small newbee, and looking for an easy way to convert a text-file.
Sinece the textfile came through ftp it has only lf at the end of the line,
but I need an cr/lf.


Thanks in advance for any help.


Best regards

Ralf
email Follow the discussionReplies 4 repliesReplies Make a reply

Similar topics

Replies

#1 McKirahan
July 21st, 2005 - 06:25 am ET | Report spam
"Ralf Meuser" wrote in message
news:42df6def$0$8112$
Hi there


I'm a very small newbee, and looking for an easy way to convert a


text-file.
Sinece the textfile came through ftp it has only lf at the end of the


line,
but I need an cr/lf.


Thanks in advance for any help.


Best regards

Ralf





Will thus help? Watch for word-wrap.

It converts files that are dragged-and dropped onto it.
A new (converted) file is created with a ".txt" extension appended
to the full filename; thus, "filename.txt" becomes "filename.txt.txt".

If the file contains both a CR and an LF then no conversion happens.
If only CR's or LF's exist then they'll be converted to CR/LF.

A MsgBox displays the results.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "2crlf.vbs"
'*
'* Declare Variables
'*
Dim boo_CR
Dim boo_LF
Dim boo_OK
Dim intARG
Dim strARG
Dim strMSG
strMSG = "Converted files:" & vbCrLf
Dim strOTF
'*
'* Declare Objects
'*
Dim objARG
Set objARG = WScript.Arguments
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
'*
'* Convert Each Drag-and-Drop File
'*
For intARG = 0 to objARG.Count - 1
strARG = objARG(intARG)
strMSG = strMSG & vbCrLf & strARG
If objFSO.FileExists(strARG) Then
'*
'* Read File
'*
Set objOTF = objFSO.OpenTextFile(strARG,1)
strOTF = objOTF.ReadAll()
Set objOTF = Nothing
'*
'* Convert File (if applicable)
'*
boo_CR = False
boo_LF = False
If InStr(strOTF,vbCr) > 0 Then boo_CR = True
If InStr(strOTF,vbLf) > 0 Then boo_LF = True
If boo_CR And boo_LF Then
boo_OK = False
strMSG = strMSG & vbCrLf & vbTab & "(Not Converted)"
ElseIf boo_CR Then
strOTF = Replace(strOTF,vbCr,vbCrLf)
boo_OK = True
strMSG = strMSG & vbCrLf & vbTab & "(Converted CR)"
ElseIf boo_LF Then
strOTF = Replace(strOTF,vbLf,vbCrLf)
boo_OK = True
strMSG = strMSG & vbCrLf & vbTab & "(Converted LF)"
End If
'*
'* Write File
'*
If boo_OK Then
Set objOTF = objFSO.OpenTextFile(strARG & ".txt",2,True)
objOTF.Write(strOTF)
Set objOTF = Nothing
End If
Else
strMSG = strMSG & vbCrLf & vbTab & "(File Not Found)"
End If
Next
'*
'* Destroy Objects
'*
Set objARG = Nothing
Set objFSO = Nothing
'*
'* Done
'*
MsgBox strMSG,vbInformation,cVBS
Replies Reply to this message
#2 Ralf Meuser
July 21st, 2005 - 08:03 am ET | Report spam
Thanks this looks great.
But it doesn't work for me.
I did perhaps soemthing wrong.

1. I copyed your code into a textfile and named it 2crlf.vbs
2. I draged my textfile which has only $0A$ onto 2crlf.vbs
3. I get the message not converted

What did I do wrong?
Drag an Drop is not bad , but could I write batfile some like this
2crlf.vbs %1 ?

Thanks in advance

Ralf


"McKirahan" a écrit dans le message de news:

"Ralf Meuser" wrote in message
news:42df6def$0$8112$
Hi there


I'm a very small newbee, and looking for an easy way to convert a


text-file.
Sinece the textfile came through ftp it has only lf at the end of the


line,
but I need an cr/lf.


Thanks in advance for any help.


Best regards

Ralf





Will thus help? Watch for word-wrap.

It converts files that are dragged-and dropped onto it.
A new (converted) file is created with a ".txt" extension appended
to the full filename; thus, "filename.txt" becomes "filename.txt.txt".

If the file contains both a CR and an LF then no conversion happens.
If only CR's or LF's exist then they'll be converted to CR/LF.

A MsgBox displays the results.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "2crlf.vbs"
'*
'* Declare Variables
'*
Dim boo_CR
Dim boo_LF
Dim boo_OK
Dim intARG
Dim strARG
Dim strMSG
strMSG = "Converted files:" & vbCrLf
Dim strOTF
'*
'* Declare Objects
'*
Dim objARG
Set objARG = WScript.Arguments
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
'*
'* Convert Each Drag-and-Drop File
'*
For intARG = 0 to objARG.Count - 1
strARG = objARG(intARG)
strMSG = strMSG & vbCrLf & strARG
If objFSO.FileExists(strARG) Then
'*
'* Read File
'*
Set objOTF = objFSO.OpenTextFile(strARG,1)
strOTF = objOTF.ReadAll()
Set objOTF = Nothing
'*
'* Convert File (if applicable)
'*
boo_CR = False
boo_LF = False
If InStr(strOTF,vbCr) > 0 Then boo_CR = True
If InStr(strOTF,vbLf) > 0 Then boo_LF = True
If boo_CR And boo_LF Then
boo_OK = False
strMSG = strMSG & vbCrLf & vbTab & "(Not Converted)"
ElseIf boo_CR Then
strOTF = Replace(strOTF,vbCr,vbCrLf)
boo_OK = True
strMSG = strMSG & vbCrLf & vbTab & "(Converted CR)"
ElseIf boo_LF Then
strOTF = Replace(strOTF,vbLf,vbCrLf)
boo_OK = True
strMSG = strMSG & vbCrLf & vbTab & "(Converted LF)"
End If
'*
'* Write File
'*
If boo_OK Then
Set objOTF = objFSO.OpenTextFile(strARG & ".txt",2,True)
objOTF.Write(strOTF)
Set objOTF = Nothing
End If
Else
strMSG = strMSG & vbCrLf & vbTab & "(File Not Found)"
End If
Next
'*
'* Destroy Objects
'*
Set objARG = Nothing
Set objFSO = Nothing
'*
'* Done
'*
MsgBox strMSG,vbInformation,cVBS




Replies Reply to this message
#3 McKirahan
July 21st, 2005 - 08:50 am ET | Report spam
"Ralf Meuser" wrote in message
news:42df8f25$0$14248$
Thanks this looks great.
But it doesn't work for me.
I did perhaps soemthing wrong.

1. I copyed your code into a textfile and named it 2crlf.vbs
2. I draged my textfile which has only $0A$ onto 2crlf.vbs
3. I get the message not converted

What did I do wrong?
Drag an Drop is not bad , but could I write batfile some like this
2crlf.vbs %1 ?

Thanks in advance

Ralf




[snip]

Apparently your file has at least on CR/LF character.

I tried it on a one byte file that only contains ASC(10) and it worked.

The program reports " (Not Converted)"
as I don't want to convert CR/LF into CR/CR/LF or CR/LF/LF.

It will run from the command line:
cscript.exe //nologo 2crlf.vbs $0A$

Thus, you could have a batch file that calls it:

@echo off
echo 2crlf.bat
echo.
cscript.exe //nologo 2crlf.vbs %1

and use it like:
2crlf.bat $0A$
Replies Reply to this message
#4 Ralf Meuser
July 21st, 2005 - 09:34 am ET | Report spam
Thanks a lot it works perfect

bye

Ralf


"McKirahan" a écrit dans le message de
news:
"Ralf Meuser" wrote in message
news:42df8f25$0$14248$
Thanks this looks great.
But it doesn't work for me.
I did perhaps soemthing wrong.

1. I copyed your code into a textfile and named it 2crlf.vbs
2. I draged my textfile which has only $0A$ onto 2crlf.vbs
3. I get the message not converted

What did I do wrong?
Drag an Drop is not bad , but could I write batfile some like this
2crlf.vbs %1 ?

Thanks in advance

Ralf




[snip]

Apparently your file has at least on CR/LF character.

I tried it on a one byte file that only contains ASC(10) and it worked.

The program reports " (Not Converted)"
as I don't want to convert CR/LF into CR/CR/LF or CR/LF/LF.

It will run from the command line:
cscript.exe //nologo 2crlf.vbs $0A$

Thus, you could have a batch file that calls it:

@echo off
echo 2crlf.bat
echo.
cscript.exe //nologo 2crlf.vbs %1

and use it like:
2crlf.bat $0A$




email Follow the discussion Replies Reply to this message
Help Create a new topicReplies Make a reply
Search Make your own search