R
R
Roman Ratkin2019-03-19 16:52:36
PowerShell
Roman Ratkin, 2019-03-19 16:52:36

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

3 answer(s)
R
Roman Ratkin, 2019-03-19
@Hanharr

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+$","" }

#
#, 2019-03-19
@mindtester

coding. ranging from cmd/powershell to whatever your heart desires

W
Winntuk, 2019-03-19
@winntuk

I think to take a list of folders, get its name, compare the last character, if it matches a space, then delete it, in the above script, if it suddenly works, all folders that have more than 1 word in the name will become single-word if you remove the space.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question