将特定目录中的所有文件转换为xml(批处理)
我想将特定目录中的所有pcap文件转换为同一目录中的xml e、 g:将特定目录中的所有文件转换为xml(批处理),xml,batch-file,powershell,Xml,Batch File,Powershell,我想将特定目录中的所有pcap文件转换为同一目录中的xml e、 g: aaa.pcap->aaa.xml bbb.pcap->bbb.xml 我想这样做: tshark -r aaa.pcap -T psml > bbb.xml 如果我再次执行批处理文件,它应该只转换新的pcap文件。e、 g 不是aaa.pcap->aaa.xml 仅ccc.pcap->ccc.xml 有人能帮我吗? 备选方案:Powershell尝试以下方法: Get-ChildItem *.pcap |
- aaa.pcap->aaa.xml
- bbb.pcap->bbb.xml
tshark -r aaa.pcap -T psml > bbb.xml
如果我再次执行批处理文件,它应该只转换新的pcap文件。e、 g
- 不是aaa.pcap->aaa.xml
- 仅ccc.pcap->ccc.xml
Get-ChildItem *.pcap | Where {!(Test-Path "$($_.BaseName).xml")} |
Foreach {tshark -r $_.FullName -T psml > "$($_.BaseName).xml"}
或简写版:
ls *.pcap | ?{!(Test-Path "$($_.BaseName).xml")} | %{tshark -r $_.FullName -T psml > "$($_.BaseName).xml"}
以下一行程序将在命令行上运行,而不需要任何批处理文件
for %F in (*.pcap) do if not exist "%~dpnF.xml" tshark -r "%F" -T psml >"%~dpnF.xml"
如果要将命令放入批处理文件中,则必须将百分比加倍
for %%F in (*.pcap) do if not exist "%%~dpnF.xml" tshark -r "%%F" -T psml >"%%~dpnF.xml"
如果要转换不在当前目录中的文件,可以在in()子句中包含路径信息