hello. I want to understand how to do this. I want to modify each .txt files from a folder, but keeping the original name on save.
I believe I made something wrong. Can you help me, please?
((Get-Content -Path 'C:\Folder1' -Filter '*.txt' -Raw -Encoding UTF8) -split "\s+" |
Sort-Object {Get-Random} ) -join ' ' |
Out-File -FilePath "$newfilename" -force
I get this error:
Get-Content : Could not find a part of the path 'C:\Folder1\'.
At line:1 char:3
+ ((Get-Content -Path 'C:\Folder1\' -Filter '*.txt' -Raw -Encodi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Folder1\:String) [Get-Content], DirectoryNotFoundException
+ FullyQualifiedErrorId : GetContentReaderDirectoryNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand
Out-File : Cannot bind argument to parameter 'FilePath' because it is an empty string.
At line:3 char:28
+ Out-File -FilePath "$newfilename" -force
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Out-File], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.OutF
ileCommand