Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Piping dir to tree

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-14-2008   #1 (permalink)
Steven Smith
Guest


 

Piping dir to tree

I'm trying to create Word documents containing the output of a "tree"
command... we need to make a sitemap of our website's actual structure to
compare it to the theoretical structure.

For each folder under webroot/dept/ I would like a separate file with the
output of the "tree" command.

What am I doing wrong? When I invoke the following command inside the /dept
folder it does absolutely nothing... doesn't even throw an error.



dir | foreach {tree >$_.doc}


Thanks!


Steven L Smith



My System SpecsSystem Spec
Old 05-14-2008   #2 (permalink)
Marco Shaw [MVP]
Guest


 

Re: Piping dir to tree

Quote:

> dir | foreach {tree >$_.doc}
I think you're basically missing where you have to cd into that
directory, and then do a tree.

Try this:
pushd
get-childitem . -recurse|
where-object{$_.psiscontainer}|
foreach-object{set-location $_.fullname;$_.fullname;tree}
popd

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 05-14-2008   #3 (permalink)
Jeff
Guest


 

Re: Piping dir to tree

On May 15, 10:31 am, Steven Smith <ssmith46_from_naz_edu> wrote:
Quote:

> I'm trying to create Word documents containing the output of a "tree"
> command... we need to make a sitemap of our website's actual structure to
> compare it to the theoretical structure.
>
> For each folder under webroot/dept/ I would like a separate file with the
> output of the "tree" command.
>
> What am I doing wrong? When I invoke the following command inside the /dept
> folder it does absolutely nothing... doesn't even throw an error.
>
> dir | foreach {tree >$_.doc}
>
> Thanks!
>
> Steven L Smith
Steven,

I think this is what you want:

Get-ChildItem -Recurse | Where-Object { $_.PSIsContainer } | ForEach-
Object { tree $_ > "$( $_.Name ).doc" }

The Where-Object Cmdlet is there to make sure tree only processes
directories. Take out the Recurse parameter if you only want the
directories directly under your current directory.

Jeff
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Piping regex match to commands Klaus H. Probst PowerShell 2 07-24-2008 03:36 PM
What is the syntax for piping LiteralPath to Get-ChildItem Bob Landau PowerShell 6 10-05-2007 10:59 PM
piping/redirect to file slow Ben Schwehn PowerShell 10 09-19-2007 07:34 AM
All about piping Marco Shaw PowerShell 2 11-20-2006 11:20 AM
New to ps object piping Adam Murray PowerShell 2 09-14-2006 02:14 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51