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.