[英]How to cut xml files and move them to a different location based on nodes via powershell , batchfile
我需要根据节点剪切或移动XML文件,等等。我想搜索整个文件,选择EG FX,然后将包含tfx的文件移动到其他位置
我尝试了以下失败的尝试
$dir = 'C:\temp\source'
Get-ChildItem -Path $dir -Filter *.xml | Foreach-Object {
$Instrument = Select-Xml -Xpath '/deal' -Path $_.FullName -ErrorAction SilentlyContinue
If($Instrument.node.innertext -eq "FX_Cross"){
Move-Item "C:\temp\source\*.xml" "C:\temp\destination\FX" -Force
} Else{
Move-Item "C:\temp\source\*.xml" "C:\temp\destination\" -Force
}
}
上面没有结果不运行
您在那儿很费力(我想,我确实需要您的XML文件样本),我想您已经在这里挂了
Move-Item "C:\temp\source\*.xml" "C:\temp\destination\FX" -Force
使用这一行代码,您要说的是移动所有XML文件,我想您应该只在循环中引用当前文件。 在这里(重写了一点点以便于调试ForEach
循环)。
$dir = 'C:\temp\source'
$xmlFiles = Get-ChildItem -Path $dir -Filter *xml
ForEach($xmlFile in $xmlFiles){
$Instrument = Select-Xml -Xpath '/deal' -Path $xmlFile.FullName -ErrorAction SilentlyContinue
If($Instrument.node.innertext -eq "FX_Cross"){
Move-Item -Path $xmlFile.FullName -Destination "C:\temp\destination\FX" -Force
}
Else{
Move-Item -Path $xmlFile.FullName -Destination "C:\temp\destination\" -Force
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.