Skip to content

Instantly share code, notes, and snippets.

@ConstantineK
Created August 29, 2019 13:33
Show Gist options
  • Save ConstantineK/92238908298b33e435ffe258d4d82780 to your computer and use it in GitHub Desktop.
Save ConstantineK/92238908298b33e435ffe258d4d82780 to your computer and use it in GitHub Desktop.
updating_spaces_in_files
# write what we want, then use it in a loop
function Update-Spaces {
param ($path)
$contents = Get-Content $path
$contents -replace "\s+",", " | Set-Content $path -Force
}
# now say we have multiple files, we need to loop and rewrite
# for each file in the folder that the script provides, filtering files that contain the filter
foreach ($file in (Get-ChildItem $PSScriptRoot -Filter "*test*.txt" -File)){
# pass the file path to the function where we manipulate it
Update-Spaces -path $file.FullName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment