Created
March 6, 2017 16:00
-
-
Save shiitake/362765041073ce768706b6eb724dd20d to your computer and use it in GitHub Desktop.
PowerShell- Remove double quotes from csv files in a directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$currentPath = (get-item -Path ".\" -Verbose).FullName | |
$outputPath = Join-Path $currentPath "fixed" | |
if (!(Test-Path $outputPath)) { | |
New-Item -ItemType Directory -Path $outputPath | Out-Null | |
} | |
$count = 0 | |
Get-ChildItem $currentPath -Filter "*.csv" | | |
Foreach-Object { | |
$content = Get-Content $_.FullName | |
#remove double quotes at the start and end of line | |
$startAndEnd = [regex]("^`"|`"$") | |
#remove double quotes before and after commas | |
$aroundCommas = [regex]("`",`"|`",|,`"") | |
#filter and save content to a new file | |
$content | Foreach-Object {$_ -replace $startAndEnd, ''` | |
-replace $aroundCommas, ','} ` | |
| Set-Content ($outputPath + "\" + $_.Name) | |
$count++ | |
} | |
Write-Host "Fixed file count: "$count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This caused my columns to become misaligned.