|
Re: Why does get-content on a text file remove crlf when cast to a string? "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:eQPKdDA3GHA.2228@TK2MSFTNGP03.phx.gbl...
Thanks Alex.
> Get-Content reads a file as a set of lines.
>
> You can use alternative characters as the record delimiter if you want;
> for example, you can force it to assume that the delimiter should be the
> null character by using this:
>
> gc AssemblyInfo.cs -Delimiter `0
>
> This ensures you get back a complete raw string.
>
>
>
> "Mark" <mwatts at hotmail dot com> wrote in message
> news:4DBDB20F-A444-47F4-AA33-419B4C2B3C99@microsoft.com...
>>
>> Given the following:
>>
>> function doWork($fileContent)
>> {
>> write-output $fileContent
>> }
>>
>> gci . -i AssemblyInfo.cs -r | % { doWork (gc $_.FullName) }
>>
>> will result in the contents of all AssemblyInfo.cs files being dumped to
>> the screen. However, this
>>
>> function doWork([string]$fileContent)
>> {
>> write-output $fileContent
>> }
>>
>> gci . -i AssemblyInfo.cs -r | % { doWork (gc $_.FullName) }
>>
>> results in all crlf'ds being removed.
>>
>> I am trying to update version information and I have a reg-ex in 'doWork'
>> that does the updates but the problem is that whenver the results of
>> get-contents is processed as a string, all the crlf information vanishes
>> which results in corrupted files?
>>
>> What am I doing wrong?
>>
>> thanks
>> -mark
>>
>> --
>> -mark
>
> |