Get-ChildItem on Weird FolderNames

I am writing a script that will get the ACL list of folders in their directory. The problem is, they have filenames/folders with hyphens and spaced that powershell’s ‘Get-ChildItem’ fails where it thinks it does not exist.

For Example, the folder ‘Dogtopia- Arlington’ does exist, but when I run the Get Childitem command on it, it doesn’t see it.

[cfs06]: PS G:\> Get-ChildItem 'G:\Shares\Schramm\BIDDING PROJECTS\Barrington Ramp\Dogtopia - Arlington Heights\Photos\10.2.19 Site Walk\Dogtopia- Arlington '
Get-ChildItem : Cannot find path 'G:\Shares\Schramm\BIDDING PROJECTS\Barrington Ramp\Dogtopia - Arlington Heights\Photos\10.2.19 Site Walk\Dogtopia- Arlington ' because it does not exist.
    + CategoryInfo          : ObjectNotFound: (G:\Shares\Schra...pia- Arlington :String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Just to prove that it is there…

[cfs06]: PS G:\> Get-ChildItem 'G:\Shares\Schramm\BIDDING PROJECTS\Barrington Ramp\Dogtopia - Arlington Heights\Photos\10.2.19 Site Walk'
 
 
    Directory: G:\Shares\Schramm\BIDDING PROJECTS\Barrington Ramp\Dogtopia - Arlington Heights\Photos\10.2.19 Site Walk
 
 
Mode                LastWriteTime         Length Name                                                                                                                                                                               
----                -------------         ------ ----                                                                                                                                                                               
d-----        10/3/2019   9:34 AM                Dogtopia- Arlington                                                                                                                                                              
-a----        10/3/2019   9:35 AM        6923919 Photo-2019-10-02-10-20-46_6553.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        6517015 Photo-2019-10-02-10-20-50_6554.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        6710406 Photo-2019-10-02-10-20-51_6555.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        5051907 Photo-2019-10-02-10-20-53_6556.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        5980265 Photo-2019-10-02-10-20-57_6557.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        7105864 Photo-2019-10-02-10-21-19_6558.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        6567256 Photo-2019-10-02-10-21-20_6559.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        6732866 Photo-2019-10-02-10-21-22_6560.JPG                                                                                                                                                 
-a----        10/3/2019   9:35 AM        6341216 Photo-2019-10-02-10-21-24_6561.JPG

There are many different files that seem to error out. Even when I define the string in double quotes, it can’t find that item which I assume is because it has a hyphen and space in the name.

Is there a way I can accommodate these archaic naming conventions without having to rename files/folders. Renaming ‘might’ cause a bit of havoc since they use third party software that might reference files by name.

I have no way to test but have you tried using the ‘LiteralPath’ parameter?

The path in your command:
'G:\Shares\Schramm\BIDDING PROJECTS\Barrington Ramp\Dogtopia - Arlington Heights\Photos\10.2.19 Site Walk\Dogtopia- Arlington ’
has an extra space at the end. Does the actual directory name have this trailing space?

You could also use the wildcard:
‘G:\Shares\Schramm\BIDDING PROJECTS\Barrington Ramp\Dogtopia - Arlington Heights\Photos\10.2.19 Site Walk\Dog**’

The gentleman asking the question, about challenging subdirectory names, (or even filenames) has a very valid question to ask.

Seems as though, true developers are jumping around his question when it could be responded to directly, yes?*

*-And I’m very aware there are several different ways to address this challenge that we all get thrust onto, one globally, and the second explicitly.

Can anyone speak to these two methods precisely?

Ok, that’s my two cents.

Thanks folks!

Cheers

I think Grokkit has it figured, but we have not heard back.

I tested with similar folders as the original post and had no issues at all.

My $.02

This appears to be the issue of trailing spaces in the folder and not the hyphen as Grokkit has pointed out. When I go to said folder above, I can’t rename it, delete it nor when I look at the security tab within Properties, I see “The requested security information is either unavailable or cant’ be displayed.”

The folder does not have a shortname as I see from the output ‘dir /x’, but it seems I have to address that issue and not so much the issue to get a complete ACL report on these folders.

 

For some reason, your sentences are truncated. This site seems to do that at random. Not sure why. So, it is hard for me to get your drift.

If the folder is longer then 8 chars, it will have a shortname unless you have that turned off.

https://support.microsoft.com/en-us/topic/how-to-disable-8-3-file-name-creation-on-ntfs-partitions-18496ea0-d086-701a-f4a5-17c05d370cf6

Glad you got it figured.

 

I suspect it happens when you insert code with the “<>” code formating tool from the “Visual” view and disable the line wrapping.
In this case the controls move to the right outside of the screen size without having scroll bars to reach them.

The issue with text being cut off is due to very long strings that the forum doesn’t break and wrap to the next line. Here is a demo.

Unfortunately, this is not a result of any specific formatting that can be avoided while posting.
It is an issue with the bbPress software and the theme that we are using for the forum. The post blocks adjust to fit the width of the content,
but the display area that the post blocks are contained in has a fixed maximum width, so if the post blocks are too wide they break the edge of
the display area. All post blocks are scaled to the same width, so if one block is too wide then all of them display inccorectly.

In this case, it’s the very long file path causing the problem. I could edit the post to make it display better (I did a little bit), but
because the file path is the issue I couldn’t change the post too much without affecting the content.

In instances like this, the text is still being written to the page, it’s just hidden.
When I need to read something from a post like this, I select the text and paste it into notepad.

Good to know. Thanks Grokkit :slight_smile: