Answer the question
In order to leave comments, you need to log in
How to find and rename directories with a space at the end of the name?
Good day to all.
Tell me how to find and rename directories with a space at the end of the name? If you recursively traverse directories, then an exception is thrown.
I can get a list of such directories:
Get-ChildItem "path" -Recurse -Directory -ErrorAction SilentlyContinue | Where-Object {$_.Name -match '\s$'}
Answer the question
In order to leave comments, you need to log in
The problem was solved in the following way
Get-ChildItem "\\?\d:\4out\" -Recurse -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match "\s+$" } |
Rename-Item -NewName { $_.Name -Replace "\s+$","" }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question