Fui procurar uma coisa e achei outra.
Deixar registrado aqui.
É um arquivo do Windows 10, um script em VB.
Está usando ADODB.Stream, que é parte do ADO, e serve pra ler uma sequência de bytes.
Mas acabou chamando a atenção:
Tem função específica LenB(), AscB() e MidB(), lembra o que é usado no Harbour.
E tem a parte de detecção se o arquivo é ASCII, UNICODE ou UTF-8.
Só achei esquisito, inicialmente, que lê 2 bytes, e compara se é >= 3, mas provavelmente porque a leitura é em caracteres, que podem ser formados por mais de um byte.
Tem em tudo que é Windows, slmgr.vbs
Mas tem muitos outros VBS no Windows.
Detectar se arquivo é Ascii, Unicode ou UTF-8
Moderador: Moderadores
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
Detectar se arquivo é Ascii, Unicode ou UTF-8
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- mauricioportela
- Usuário Nível 2

- Mensagens: 95
- Registrado em: 29 Jul 2016 04:22
- Localização: Vitoria da Conquista/Bahia
Detectar se arquivo é Ascii, Unicode ou UTF-8
Eu to trabalhando em algo que identifique alguns arquivos (quando estes são renomeados).
espero que isso ajude voce.
Att.
Mauricio Portela
Código: Selecionar todos
/*
File signature - https://pt.jejakjabar.com/wiki/List_of_file_signatures
Magic number - https://pt.jejakjabar.com/wiki/Magic_number_(programming)
*/
#include "Directry.ch"
#include "fileio.ch"
function main()
aDir := Directory("*.*")
cNovoArquivo := ""
nContador := 1
cArquivo_UniCode1 := CHR(ft_Hex2Dec("EF")) + CHR(ft_Hex2Dec("BB")) + ;
CHR(ft_Hex2Dec("BF"))
cArquivo_UniCode2 := CHR(ft_Hex2Dec("FF")) + CHR(ft_Hex2Dec("FE"))
cArquivo_UniCode3 := CHR(ft_Hex2Dec("FF")) + CHR(ft_Hex2Dec("FE")) + ;
CHR(ft_Hex2Dec("00")) + CHR(ft_Hex2Dec("00"))
cArquivo_ASCII := CHR(ft_Hex2Dec("3c")) + CHR(ft_Hex2Dec("3f")) + ;
CHR(ft_Hex2Dec("78")) + CHR(ft_Hex2Dec("6d")) + ;
CHR(ft_Hex2Dec("6c")) + CHR(ft_Hex2Dec("20"))
for i := 1 TO LEN(aDir)
cBuffer := Space(64)
cArquivo := ""
? strzero(nContador,6), "Arquivo:", aDir[i,F_NAME]
if (aDir[i,F_NAME] == "." .OR. aDir[i,F_NAME] == "..")
else
if (nH := fOpen(aDir[i,F_NAME])) != F_ERROR
fRead( nH, @cBuffer, 16 )
fClose( nH )
else
? "Arquivo nao pode ser aberto."
return Nil
endif
if (substr( cbuffer, 1, 2 ) == "PK")
flag := .T.
cNovoArquivo := "Arquivo_Compactado_ZIP_" + strzero(nContador,4) + ".zip"
elseif (substr( cbuffer, 1, 2 ) == "MZ")
flag := .T.
cNovoArquivo := "Arquivo_Binario_" + strzero(nContador,4) + ".exe"
elseif (substr( cbuffer, 2, 3 ) == "PNG")
flag := .T.
cNovoArquivo := "Imagem_PNG_" + strzero(nContador,4) + ".png"
elseif (substr( cbuffer, 7, 4 ) == "JFIF")
flag := .T.
cNovoArquivo := "Imagem_JPEG_" + strzero(nContador,4) + ".jpeg"
elseif (substr( cbuffer, 1, 5 ) == "GIF89")
flag := .T.
cNovoArquivo := "Imagem_GIF_" + strzero(nContador,4) + ".gif"
elseif (substr( cbuffer, 1, 4 ) == "%PDF")
flag := .T.
cNovoArquivo := "Arquivo_PDF_" + strzero(nContador,4) + ".pdf"
elseif (substr( cbuffer, 1, 4 ) == "ITSF")
flag := .T.
cNovoArquivo := "Arquivo_Ajuda_Windows_" + strzero(nContador,4) + ".chm"
elseif (substr( cbuffer, 7, 4 ) == "Exif")
flag := .T.
cNovoArquivo := "Imagem_com_Localizacao_" + strzero(nContador,4) + ".png"
elseif (substr( cbuffer, 1, 3 ) == "Rar")
flag := .T.
cNovoArquivo := "Arquivo_Compactado_RAR_" + strzero(nContador,4) + ".rar"
elseif (substr( cbuffer, 1, 3 ) == cArquivo_UniCode1)
flag := .T.
cNovoArquivo := "Arquivo_UniCode_Tipo_1_" + strzero(nContador,4) + ".txt"
elseif (substr( cbuffer, 1, 2 ) == cArquivo_UniCode2)
flag := .T.
cNovoArquivo := "Arquivo_UniCode_Tipo_2_" + strzero(nContador,4) + ".txt"
elseif (substr( cbuffer, 1, 4 ) == cArquivo_UniCode3)
flag := .T.
cNovoArquivo := "Arquivo_UniCode_Tipo_3_" + strzero(nContador,4) + ".txt"
elseif (substr( cbuffer, 1, 6 ) == cArquivo_ASCII)
flag := .T.
cNovoArquivo := "Arquivo_ASCII_" + strzero(nContador,4) + ".txt"
endif
if flag
cArquivo := alltrim(aDir[i,F_NAME])
else
cArquivo := "*"
endif
endif
if ( cArquivo == "*" )
else
nResult := FRename( cArquivo, cNovoArquivo )
if nResult != 0
? "ATENCAO!", cArquivo, "Arquivo nao pode ser renomeado!"
endif
endif
nContador++
next
return Nil
Att.
Mauricio Portela
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
Detectar se arquivo é Ascii, Unicode ou UTF-8
Achei Interessante.
Veja se interessa o fonte modificado.
Pode facilitar incluir mais tipos.
Veja se interessa o fonte modificado.
Pode facilitar incluir mais tipos.
Código: Selecionar todos
/*
File signature - https://pt.jejakjabar.com/wiki/List_of_file_signatures
Magic number - https://pt.jejakjabar.com/wiki/Magic_number_(programming)
*/
REQUEST HB_CODEPAGE_PTISO
#include "Directry.ch"
#include "fileio.ch"
FUNCTION main()
LOCAL nHandle, aFile, aConfig, cBuffer, aFileList := Directory( "*.*" )
LOCAL aList := { ;
{ 1, 2, "PK", "compactado ZIP" }, ;
{ 1, 2, "MZ", "binário" }, ;
{ 2, 3, "PNG", "imagem PNG" }, ;
{ 7, 4, "JFIF", "imagem JPEG" }, ;
{ 1, 5, "GIF89", "imagem GIF" }, ;
{ 1, 4, "%PDF", "PDF" }, ;
{ 1, 4, "ITSF", "ajuda Windows" }, ;
{ 7, 4, "Exif", "imagem com localização" }, ;
{ 1, 3, "Rar", "compactado RAR" }, ;
{ 1, 3, Chr(ft_Hex2Dec("EF")) + Chr(ft_Hex2Dec("BB")) + ;
Chr(ft_Hex2Dec("BF")), "Unicode Tipo 1" }, ;
{ 1, 2, Chr(ft_Hex2Dec("FF")) + Chr(ft_Hex2Dec("FE")), "Unicode Tipo 2" }, ;
{ 1, 4, Chr(ft_Hex2Dec("FF")) + Chr(ft_Hex2Dec("FE")) + ;
Chr(ft_Hex2Dec("00")) + Chr(ft_Hex2Dec("00")), "Unicode Tipo 3" }, ;
{ 1, 6, Chr(ft_Hex2Dec("3c")) + Chr(ft_Hex2Dec("3f")) + ;
Chr(ft_Hex2Dec("78")) + Chr(ft_Hex2Dec("6d")) + ;
Chr(ft_Hex2Dec("6c")) + Chr(ft_Hex2Dec("20")), "ASCII" } }
Set( _SET_CODEPAGE, "PTISO" )
FOR EACH aFile IN aFileList
? StrZero( aFile:__EnumIndex, 6 ), "Arquivo:", aFile[ F_NAME ]
IF ! "D" $ aFile[ F_ATTR ]
IF ! ( nHandle := fOpen( aFile[ F_NAME ] ) ) > 0
? "Arquivo nao pode ser aberto."
LOOP
ENDIF
cBuffer := fReadStr( nHandle, 16 )
fClose( nHandle )
FOR EACH aConfig IN aList
IF Substr( cBuffer, aConfig[ 1 ], aConfig[ 2 ] ) == aConfig[ 3 ]
? "Arquivo " + aConfig[ 4 ]
EXIT
ENDIF
NEXT
ENDIF
NEXT
RETURN Nil
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
Detectar se arquivo é Ascii, Unicode ou UTF-8
Faça um teste também assim:
Código: Selecionar todos
FOR EACH aFile IN Directory( "*.*" )
? aFile[ F_NAME ], hb_MimeFile( aFile[ F_NAME ] )
NEXT
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- mauricioportela
- Usuário Nível 2

- Mensagens: 95
- Registrado em: 29 Jul 2016 04:22
- Localização: Vitoria da Conquista/Bahia
Detectar se arquivo é Ascii, Unicode ou UTF-8
Quintas, bom dia!
Excelente! Ficou mais refinado!
Obrigado!
Att.
Mauricio Portela
Excelente! Ficou mais refinado!
Obrigado!
Att.
Mauricio Portela