Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Removing Leading spaces from Folder Names

$
0
0

I have a bunch of folder many layers deep many of which have a leading space in the name - ask a mac user why they would do this cos I don't know.

Anyway I need to get rid of the leading spaces so I tried this

{
            If($folder.name.length -ne $folder.name.Trim().length) 
            {
        Rename-Item -Path $folder.name $folder.name.Trim()
}

But this doesn't work.

It recognizes that the length of the folder names are different  so can distinguish between "Archive" and " Archive" but will not change and the error give n is that " Archive" does not exist.

I'm new to Powershell so I think I'm in over my head.

Please help   


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>