How about this?
Get-ChildItem c:\junk\123*.txt |
ForEach-Object{
$x = Get-Content $_
[Array]::Reverse($x)
$x |
Out-File $_
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This script, saved to a .ps1 file which I run as an admin is not working:-
$x = Get-Content -Path C:\Users\SKY\Desktop\curede*.*
$x | Out-File -FilePath C:\Users\SKY\Desktop\curede*.*
Please tell me how to reverse the order of the lines in multiple files of a folder with a PowerShell script.
How about this?
Get-ChildItem c:\junk\123*.txt |
ForEach-Object{
$x = Get-Content $_
[Array]::Reverse($x)
$x |
Out-File $_
}
Are there sub-directories beneath "C:\Users\SKY\Desktop\curede\"? The Get-ChildItem, as written by you, will return not only files but also directories. If you only want files, add the "-File" parameter.
Note that the code I posted had no need for the "-File" parameter, nor does it include any error checking (e.g., what if $x contains a $null value?).