Get-ChildItem . -Recurse | Foreach { IF ($_.Length -gt "1") { Rename-Item -Path $_.FullName -NewName Test.txt } }
Rudimentary, just trying to work around this issue, plan to use replace eventually but tried to reduce complexity to figure it out.
Scenario:
1) Create a folder.
2) Create a txt file with some content inside of it.
3) Rename txt file: Some File Name.txt.
4) Run script. Result Test.txt.
5) Rename Test.txt to: [anything] Some File Name.txt.
6) Run script. Cannot find path to file even though full literal is listed.
Issue is obviously something to do with special characters.. just no idea how to work around it.
submitted by /u/Gorstag
[link] [comments]
The post Rename-Item can’t find file due to special characters. appeared first on How to Code .NET.