【发布时间】:2018-10-31 11:17:12
【问题描述】:
我一直在尝试编写一个脚本来更改特定目录中一组文件的文件编码和文件扩展名,但无济于事。到目前为止,get-content 和 set-content 方法一直在工作,但仅适用于单个文件(还没有让它循环)。
即
get-content testdocument.txt | set-content -encoding utf8 "testdocument.xml"
#works!
即
$a = dir |
$a foreach-object |
get-content | set-content -encoding utf8 $a_fullname.xml
#doesn't work =(
我在 rename-item cmdlet 方面也取得了成功(有限)。我可以重命名目录中的所有项目,但无法更改编码。
即
get-childitem *.txt | rename-item -newname {$_.name -replace '.txt','.xml'}
#works!
即
get-childitem *.txt | rename-item -newname {$_.name -replace '.txt','.xml'} | -encoding utf8
#doesn't work =(
任何帮助将不胜感激。如果这个问题看起来微不足道,我深表歉意(通常是 Powershell/脚本的新手,也是第一次发布)。提前致谢!
【问题讨论】:
标签: xml powershell loops