Problem with VBS and XML

0
Are people ... all right? I have a problem here, I have a VBS script that caters me well, it reads the XML files and renames them to the vendor name.

Now I need it to rename the XML to the document issuance date (dhEmi), which in this case is a DACTE. I tried to do it here but it does not work ... Could you help me? Here are the codes:

XML snippet:

<?xml version = "1.0" encoding = "ISO-8859-1"?>
<cteProc versao="3.00" xmlns="http://www.portalfiscal.inf.br/cte">
    <CTe xmlns="http://www.portalfiscal.inf.br/cte">
        <infCte versao="3.00" Id="CTe33180702012862001050570060001000081465016982">
            <ide>
                <cUF>33</cUF>
                <cCT>sad1698</cCT>
                <CFOP>6asd351</CFOP>
                <natOp>PREST. SERV DE TRANSP. PARA EXECUÇÃO SERV. DA MESMA NATUREZA</natOp>
                <mod>57</mod>
                <serie>6</serie>
                <nCT>10s0008</nCT>
                <dhEmi>2018-07-17T15:37:34-03:00</dhEmi>
                <tpImp>1</tpImp>
                <tpEmis>1</tpEmis>
                <cDV>2</cDV>
                <tpAmb>1</tpAmb>
                <tpCTe>0</tpCTe>
                <procEmi>0</procEmi>
                <verProc>Triangulus_2.0.28.48</verProc>
                <cMunEnv>3304557</cMunEnv>
                <xMunEnv>RIO DE JANEIRO</xMunEnv>
                <UFEnv>RJ</UFEnv>
                <modal>02</modal>
                <tpServ>0</tpServ>
                <cMunIni>3304557</cMunIni>
                <xMunIni>RIO DE JANEIRO</xMunIni>
                <UFIni>RJ</UFIni>
                <cMunFim>3518800</cMunFim>
                <xMunFim>GUARULHOS</xMunFim>
                <UFFim>SP</UFFim>
                <retira>0</retira>
                <xDetRetira>AEROPORTO</xDetRetira>
                <indIEToma>1</indIEToma>
                <toma3>
                    <toma>3</toma>
                </toma3>
            </ide>
            <compl>
                <xCaracSer>PRÓXIMO DIA</xCaracSer>
                <xEmi>Tauany Peçanha Ayre</xEmi>
                <fluxo>
                    <xOrig>SDU</xOrig>
                    <xDest>GRU</xDest>
                </fluxo>
                <destCalc>3518800</destCalc>
                <xObs>ICMS CONFORME RESOLU??O DO SENADO FEDERAL 95/96</xObs>
                <ObsCont xCampo="TIPO DE PAGAMENTO">
                    <xTexto>CONTA CORRENTE - 638877SAO - 19.89</xTexto>
                </ObsCont>
                <ObsCont xCampo="CONTA CORRENTE">
                    <xTexto>638877SAO</xTexto>
                </ObsCont>
                <ObsCont xCampo="FINANCIERO">
                    <xTexto>Lei da transparência 12.741/12, o percentual aproximado dos tributos incidentes sobre o preço do serviço são: Federal: 15,96% Estadual: 4,0%</xTexto>
                </ObsCont>
            </compl>
            <emit>
                <CNPJ>02012862001050</CNPJ>
                <IE>84328820</IE>
                <xNome>TAM LINHAS AEREAS SA SDU</xNome>
                <enderEmit>
                    <xLgr>PC SENADOR SALGADO FILHO</xLgr>
                    <nro>0</nro>
                    <xCpl>AEROPORTO SANTOS DUMONT</xCpl>
                    <xBairro>AEROPORTO SANTOS DUMONT</xBairro>
                    <cMun>3304557</cMun>
                    <xMun>RIO DE JANEIRO</xMun>
                    <CEP>20021340</CEP>

VBS file:

DiretorioobjFiles = "C:\DACTE\"
DiretorioDestino = "C:\DACTE\DATA\"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = FSO.GetFolder(DiretorioobjFiles)
Wscript.Echo objFolder.Path

Set colFiles = objFolder.Files


For Each objFile in colFiles

On Error Resume Next
If Right(objFile.FileName, 4) = ".xml" Then

    Set objParser = CreateObject("Microsoft.XMLDOM")
    objParser.Load (objFile.path)

    Set ElemList = objParser.getElementsByTagName("chNFe")
    FilePath = ElemList.Item(0).getAttribute("filePath")

    oldFileName = objFile.path

    Set ElemList = objParser.getElementsByTagName("dhEmi")
    dhEmi = ElemList.Item(0).Text

    newFileName = DiretorioDestino + dhEmi + ".xml"

    fso.MoveFile oldFileName, newFileName
End If
Next

Thank you!

    
asked by anonymous 08.08.2018 / 23:43

1 answer

0

It seems like it is not working because it is trying to save a file that contains : in the middle of the name.

<dhEmi>2018-07-17T15:37:34-03:00</dhEmi>

You can change the code to something like this: (you can use another character)

dhEmi = Replace(ElemList.Item(0).Text, ":", "_")

newFileName = DiretorioDestino + dhEmi + ".xml"
    
09.08.2018 / 00:48