Powershell Directory Tree
-
Hey All,
Looking for a decent way to scan for and create a directory tree 3 levels deep, and not list any files within the tree it's self.
I have this
Get-ChildItem -Path Q:\ -Recurse | Export-Csv C:\File-Tree.cs
which works mostly, but is adding all of the files and every sub folder.Any input to help simplify this?
-
I ideally would like something along these lines.
Q:\ - - - Q:\Folder 1 - - - - Q:\Folder 1\Sub 1 - - - - - Q:\Folder 1\Sub 1\ Q:\ - - - Q:\Folder 2 - - - - Q:\Folder 2\Sub 1 - - - - - Q:\Folder 2\Sub 1\
So on and so forth.
-
get-childitem -Path Q:\ -Recurse -Directory -Depth 3|export-csv C:\file-tree.csv
Just missing -directory and -Depth options.
Edit: You added additional requirements after I posted that, lol.
-
@dafyre said in Powershell Directory Tree:
get-childitem -Path Q:\ -Recurse -Directory -Depth 3|export-csv C:\file-tree.csv
Just missing -directory and -Depth options.
Testing now.
-
@dustinb3403 said in Powershell Directory Tree:
@dafyre said in Powershell Directory Tree:
get-childitem -Path Q:\ -Recurse -Directory -Depth 3|export-csv C:\file-tree.csv
Just missing -directory and -Depth options.
Testing now.
Slight modification:
get-childitem -Path Q:\ -Recurse -Directory -Depth 3|select FullName|export-csv C:\file-tree.csv
Will get you just the folder list.
-
It went more than the 3 directories though.
It's much cleaner though.
-
I got it sorted, computer math
2 means 2 from the directory its starting from (aka) 1 deeper than what I was thinking.
Set it to 1 deep and I get two folders.
Thanks!
-
@dustinb3403 You're welcome ! Glad you got it sorted.