【问题标题】:how could I replace string in the KMZ file by using powershell如何使用 powershell 替换 KMZ 文件中的字符串
【发布时间】:2012-07-12 05:32:40
【问题描述】:

我需要修改 KML/KMZ 文件中的属性字符串, 我已将 KMZ 文件解压缩到临时文件夹,需要通过 KML 文件更改名称字符串(出现时的所有名称字符串),因此 powershell 可以提供帮助,但我不太确定如何,我是新手在PowerShell中。 我怎么能这样做?请帮忙!

【问题讨论】:

    标签: powershell kml replace unzip kmz


    【解决方案1】:

    如果没有示例,此示例不准确,但您必须执行以下操作:

    (get-content c:\temp\yourfile.kml ) | % {  $_ -replace 'name','anothername' } | 
    set-content c:\temp\yourfile.kml
    

    这将任何 'name' 字符串更改为 'anothername' 字符串:

    myname it's my name  
    

    成为

    myanothername it's my anothername
    

    【讨论】:

    • 仅供参考 - 你可以在没有 ForEach-Object 的情况下做到这一点:(get-content c:\temp\yourfile.kml) -replace 'name', 'anothername' | Set-Content C:\temp\yourfile.kml。您可能想提一下,因为 OP 是 PS 初学者,所以 -replace 运算符使用正则表达式,因此可能必须转义搜索字符串中的某些字符。
    • @AndyArismendi 感谢您的精确...无论如何,请随时编辑我的答案,添加您的宝贵建议。我会很荣幸。
    猜你喜欢
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多