1 (изменено: wildwolf007, 2014-08-03 21:43:05)

Тема: VBS: Проблема с кодировкой

Перерыл форум вроде нашел решение для переделывания кодировки, но чето не получается:



Set objFso = CreateObject("Scripting.FileSystemObject")

Set File = objFso.GetFile("C:\Users\Константин_2\Desktop\1.txt")

    Set vStream = objFso.OpenTextFile(File, 1, False)   ' Открываем исходный текст файл для чтения
    FillPutSendMask = vStream.ReadAll() 
    vStream.Close                                              ' Закрываем файл


WScript.Echo StrConv(FillPutSendMask,"cp866","Windows-1251")

Function StrConv(Text,SourceCharset,DestCharset)
    Set Stream = CreateObject("ADODB.Stream")
    Stream.Type = 2
    Stream.Mode = 3
    Stream.Open
    Stream.Charset = SourceCharset
    Stream.WriteText Text
    Stream.Position = 0
    Stream.Charset = DestCharset
    StrConv = Stream.ReadText
End Function

Скажите где допустил ошибку ? Файл с кодировкой прикрепил.
Вроде через Far все получается просматривать через кнопочку F8.
http://www.fayloobmennik.net/3998969

Post's attachments

1.txt 59 b, 19 downloads since 2014-08-03 

You don't have the permssions to download the attachments of this post.

2

Re: VBS: Проблема с кодировкой

Надо наоборот — «…, "windows-1251", "cp866")», поскольку содержимое в «cp866» уже прочтено как «windows-1251»:

Option Explicit

Dim strSourceFile


strSourceFile = "E:\Песочница\0387\1.txt"

With WScript.CreateObject("Scripting.FileSystemObject")
    If .FileExists(strSourceFile) Then
        With .OpenTextFile(strSourceFile)
            WScript.Echo StrConvert(.ReadAll(), "windows-1251", "cp866")
            .Close
        End With
    Else
        WScript.Echo "Source file [" & strSourceFile & "] not found."
        WScript.Quit 1
    End If
End With

WScript.Quit 0
'=============================================================================

'=============================================================================
' HKEY_CLASSES_ROOT\MIME\Database\Charset
' cp866, windows-1251, koi8-r, unicode, utf-8, _autodetect
'=============================================================================
Function StrConvert(ByVal strText, ByVal strSourceCharset, ByVal strDestCharset)
    Const adTypeText      = 2
    Const adModeReadWrite = 3
    
    
    With WScript.CreateObject("ADODB.Stream")
        .Type      = adTypeText
        .Mode      = adModeReadWrite
        
        .Open
        
        .Charset   = strSourceCharset
        .WriteText strText
        
        .Position  = 0
        .Charset   = strDestCharset
        StrConvert = .ReadText
        
        .Close
    End With
End Function
'=============================================================================

P.S. Выкладывать же лучше на RGhost, предварительно упаковав в архив.

3

Re: VBS: Проблема с кодировкой

Спасибо за подсказку. Скажите, а зачем Вы свой код привели в пример ?

4

Re: VBS: Проблема с кодировкой

Для воспроизведения.