这是我的vb代码。这正是我想用powershell做的。
Public Sub Main()
Dim file As New System.IO.StreamReader(Dts.Variables("User::str_SourcePath").Value.ToString())
Dim data As String
data = file.ReadToEnd()
data = data.Replace("""" & vbCrLf, """" & vbLf)
data = data.Replace(vbCrLf, " ")
data = data.Replace(vbCr, vbLf)
data = data.Replace(Chr(32) & vbCrLf, vbLf)
data = data.Replace(Chr(32) & vbLf, vbLf)
data = data.Replace("'", "")
data = data.Replace(Chr(0), "")
file.Close()
Dim writer As New System.IO.StreamWriter(Dts.Variables("User::str_SourcePath").Value.ToString(), False)
writer.Write(data)
writer.Flush()
writer.Close()
Dts.TaskResult = ScriptResults.Success
End Sub
我的 Powershell 脚本:
Get-ChildItem "C:\Users\abc\Desktop\Files" | ForEach-Object {
$Content = Get-Content $_.fullname
$Content = ForEach-Object { $Content -replace "\r\n","\n" }
$Content = ForEach-Object { $Content -replace "'","" }
$Content = ForEach-Object { $Content -replace "chr(0)","" }
Set-Content $_.fullname $Content -Force
}
我正在尝试替换一些 ascii 字符控制代码(0 到 10)和(12 到 15)和(17)以及(21 到 30)。