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
>
>