朋友您好我正在尝试根据特定节点重命名一组xml文件,这些节点总是会改变位置 到目前为止,我有以下代码始终在同一位置工作,但正如我所说,我需要的位置是可变的。
我需要的节点是我在图像noIdentificacion =
中设置的节点@echo off
for /f "delims=" %%Z in ('dir /b *.xml') do (
for /f "tokens=12 delims== " %%A in (
'find /i "noIdentificacion=" ^< "%%Z"'
) do ren "%%Z" "%%A.xml"
)
我希望他们可以支持我。谢谢。
抱歉atach EG
<?xml version="1.0" encoding="UTF-8"?><cfdi:Comprobante
<cfdi:DomicilioFiscal calle="Paseo" codigoPostal="123123"
colonia="LOMAS" estado="DF" localidad="MEXICO D.F." municipio="Cuajimalpa
de
Morelos" noExterior="400B" noInterior="P3" pais="MEXICO" />
<cfdi:ExpedidoEn pais="Mexico" referencia="AA000771139" />
<cfdi:RegimenFiscal Regimen="Régimen General de las Personas Morales" />
</cfdi:Emisor>
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.00" descripcion="ROLL" importe="270505.28"
noIdentificacion="99994HWR3929" unidad="EA" valorUnitario="270505.28">
<cfdi:ComplementoConcepto>
<ventavehiculos:InformacionAduanera aduana="Eagle Pass" fecha="2017-06-19"
numero="172736007007111" />
</ventavehiculos:VentaVehiculos>
</cfdi:ComplementoConcepto>
</cfdi:Concepto>
</cfdi:Conceptos>
<cfdi:Impuestos totalImpuestosTrasladados="43943.38">
<cfdi:Traslados>
<cfdi:Traslado importe="43943.38" impuesto="IVA" tasa="16" />
</cfdi:Traslados>
</cfdi:Impuestos>
<cfdi:Complemento>
Lg4NRnJDXIqvehu8vEyugAePTdHluCgD32E=" version="1.0"
xsi:schemaLocation="http://www.sat.gob.mx/TimbreFiscalDigital
http://www.sat.gob.mx/TimbreFiscalDigital/TimbreFiscalDigital.xsd"
xmlns:tfd="http://www.sat.gob.mx/TimbreFiscalDigital" />
</cfdi:Complemento>
</cfdi:Comprobante>
答案 0 :(得分:0)
以下 评论 脚本应该可以胜任:
@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
REM Change the current directory: your choice
pushd "D:\bat\SO\files"
REM Get a static list of `xml` files
for /f "delims=" %%Z in ('dir /b *.xml') do (
set "_noIdentificacion=" REM clear a sentinel flag
REM Search for a particular text string in a file
for /f "delims=" %%A in ( 'find /i "noIdentificacion=" ^< "%%Z"' ) do (
REM The FOR command is mostly used to process a set of one or more files,
REM but you can also process a set of one or more text strings:
for %%G in ( %%A ) do (
REM debugging output
echo debug %%G
REM found the particular text string in the line?
if /I "%%~G"=="noIdentificacion" (
set "_noIdentificacion=noIdentificacion" REM set the sentinel flag
) else (
if defined _noIdentificacion (
REM debugging output
echo found noIdentificacion in file "%%~Z": "%%~G"
REM check as to whether a file isn't renamed already
if EXIST "%%~Z" if /I "%%~Z" NEQ "%%~G.xml" (
REM remove ECHO from next line no sooner than debugged
ECHO ren "%%~Z" "%%~G.xml"
)
)
set "_noIdentificacion=" REM clear the sentinel flag
)
)
)
)
REM Change directory back to the path/folder most recently stored by the PUSHD command.
popd
示例结果包含所有调试输出数据:
==> D:\bat\SO\q45449070.bat
debug <cfdi:Concepto
debug cantidad
debug "1.00"
debug descripcion
debug "ROLL"
debug importe
debug "270505.28"
debug noIdentificacion
debug "99994HWR3929"
found noIdentificacion in file "45449070.xml": "99994HWR3929"
ren "45449070.xml" "99994HWR3929.xml"
debug unidad
debug "EA"
debug valorUnitario
debug "270505.28">
==>