Hide child directory structure but keep parent directroy visible .

~OSD~ 2,131 Reputation points


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


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

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,404 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 31,091 Reputation points Microsoft Vendor


    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