Hide child directory structure but keep parent directroy visible .

~OSD~ 2,151 Reputation points
2021-02-04T19:38:37.837+00:00

Hi,

Have following directory structure at D:\ParentDir, where there exists several directories which are often randomly assigned names.

64099-image.png

I want to hide all child directories under each DynamicDir 1, DynamicDir N., something like this:
64069-image.png

If possible, would like to keep MyDemo.txt file visible if it resides under DynamicDir(s), possible with PowerShell?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 34,271 Reputation points Microsoft Vendor
    2021-02-05T06:20:47.787+00:00

    Hi,

    Please check if this works for you

    $folder = 'D:\ParentDir\'  
    $file = 'MyDemo.txt'  
    Get-childItem -Path $folder | Get-ChildItem |ForEach-Object{  
        if($_.Name -ne $file){  
            $_.Attributes -= 'Hidden'  
        }  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful