gpt4 book ai didi

windows - 将所有 .txt 文件内容转换为小写的脚本

转载 作者:可可西里 更新时间:2023-11-01 11:15:47 26 4
gpt4 key购买 nike

我有大约 700 个 .txt 文件分散在 300 个目录和子目录中。

我想打开它们中的每一个,将里面的所有文本转换为小写,包括 Unicode 字符(例如 Éé),然后保存并关闭它们。

您能建议如何通过 PowerShell 完成吗?这是我自己的电脑,我有管理员权限。

我从以下开始:

Get-ChildItem C:\tmp -Recurse -File | ForEach-Object {}

但我不确定在 ForEach-Object {} 的括号之间放什么。

最佳答案

简单的脚本,符合您的要求:

$path=".\test\*.txt"
#With Default system encoding
Get-ChildItem $path -Recurse | foreach{
(Get-Content $_.FullName).ToLower() | Out-File $_.FullName
}

#Or with specified encoding
Get-ChildItem $path -Recurse | foreach{
(Get-Content $_.FullName -Encoding Unicode).ToLower() |
Out-File $_.FullName -Encoding Unicode
}
#Test
Get-ChildItem $path -Recurse | foreach{
Write-Host "`n File ($_.FullName): `n" -ForegroundColor DarkGreen
Get-Content $_.FullName
}

关于windows - 将所有 .txt 文件内容转换为小写的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47792596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com