How could you remove blank spaces from a directory of txt files but have each file save speratley. the code snip it I have combines all the txt files into 1
heres what I have so far
@(gc (dir) -match '\S' | out-file c:\FileWithNoEmptyLines.txt
How could you remove blank spaces from a directory of txt files but have each file save speratley. the code snip it I have combines all the txt files into 1
heres what I have so far
@(gc (dir) -match '\S' | out-file c:\FileWithNoEmptyLines.txt
Hey there H Man, does this help? It’ll copy the text files, remove the spaces from the copies, and copy them back to the original dir. Might be a little dirty, but it works.
$Files = Get-ChildItem -Path C:\scripts\Spaces -File *.txt
ForEach[$File in $Files]{Copy-Item $File.FullName -Destination C:\scripts\Spaces\Changed
Rename-Item $File.FullName [$File.Name -replace " ",""]
Copy-Item -Path C:\scripts\Spaces\Changed\*.txt -Destination C:\scripts\Spaces
}
Hey WIll thanks for the response
I was looking to remove the spaces with in each message itself not the name
but thanks that’s still pretty cool how u did that
heres the code to remove the blanks internally in the file
@(gc c:\FileWithEmptyLines.txt) -match '\S' | out-file c:\FileWithNoEmptyLines
i need to save each indiviual file after the spaces are removed not as 1 whole file
i solved it
ForEach($File in $Files){
$Directory = 'C:\Testing\E\'
$path = $File.FullName
$name = $file.name
$extension = $file.extension
@(gc $path) -match '\S' | out-file "$($Directory)$($name)$($Extension)"
}