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

Re: Converting CR to CR/LF by McKirahan

McKirahan
Thu Jul 21 05:27:08 CDT 2005

"Ralf Meuser" <rmeuser@free.fr> wrote in message
news:42df6def$0$8112$626a14ce@news.free.fr...
> 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



Re: Converting CR to CR/LF by Ralf

Ralf
Thu Jul 21 07:03:47 CDT 2005

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" <News@McKirahan.com> a écrit dans le message de news:
woKdnUTn6_bh5ULfRVn-vQ@comcast.com...
> "Ralf Meuser" <rmeuser@free.fr> wrote in message
> news:42df6def$0$8112$626a14ce@news.free.fr...
>> 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
>
>



Re: Converting CR to CR/LF by McKirahan

McKirahan
Thu Jul 21 07:52:37 CDT 2005

"Ralf Meuser" <rmeuser@free.fr> wrote in message
news:42df8f25$0$14248$626a14ce@news.free.fr...
> 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$



Re: Converting CR to CR/LF by Ralf

Ralf
Thu Jul 21 08:34:32 CDT 2005

Thanks a lot it works perfect

bye

Ralf


"McKirahan" <News@McKirahan.com> a écrit dans le message de
news: -oudnaqaTbMIB0LfRVn-jg@comcast.com...
> "Ralf Meuser" <rmeuser@free.fr> wrote in message
> news:42df8f25$0$14248$626a14ce@news.free.fr...
>> 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$
>
>