Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell script to print all subfolders

I have a folder 'A' which as 2 subfolders 'A-1' & 'A-2' and 'A-1' has 2 more sub folders 'A-1-1' and 'A-1-2' under it.

I would like to display all the folder names using powershell script.

   $folders = Get-ChildItem C:\Folder\A -Directory
   foreach ($folder in $folders) {
    #For each folder in C:\banana, copy folder c:\copyme and its content to c:\banana\$folder
    #Copy-Item -Path "C:\copyme" -Destination "C:\banana\$($folder.name)" -Recurse
    write-host $folder
   }

My below script only prints :

A
A-1
A-2

I would like to print :

A
A-1
A-2
A-1-1
A-1-2

How can I do that ?

like image 487
CodeNinja Avatar asked Mar 06 '26 19:03

CodeNinja


1 Answers

Try -recurse option like this :

Get-ChildItem C:\Folder\ -Directory -recurse
like image 155
Esperento57 Avatar answered Mar 08 '26 12:03

Esperento57



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!