Here is my vb code. This is exactly what i want to do with 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
My Powershell Script:
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
}
I am trying to replace a few ascii characters control code (0 to 10) and from (12 to 15) and (17) and also from (21 to 30).