views:

173

answers:

5

Can PowerShell on Windows by itself or using simple shell script, list files and directory this way: (or using Mac OS X or Ubuntu's shell script)

audio
  mp3
    song1.mp3
    some other song.mp3
  audio books
    7 habits.mp3
video
  samples
    up.mov
    cars.mov

Unix's ls -R or ls -lR can't seem to list it in a tree structure unfortunately.

+4  A: 

You can use tree.com for listing like indented like shown above. Note that tree.com only works with the filesystem. If you ever have a need to display structure for other providers like WSMan or RegEdit, you can use the Show-Tree function that comes with the PowerShell Community Extensions.

Keith Hill
+1  A: 

In Linux, you can use:

ls -R directory | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

or for the current directory:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

You can put this "small" command in a script: look here

laurent-rpnet
hm... actually, don't know why but it doesn't work on Ubuntu 10.04... oh it seems to list only the folders, not individual files...
動靜能量
You're right, it shows only folders. It could be modified to show files too but I think you're better using the tree command suggested. I didn't knew it when I suggested this command line... Tree works perfect on Lucid and list files. (obs: you can use only "tree" or "tree folder", no need for ls -R before).
laurent-rpnet
+1  A: 

you can use Unix's tree command, or if you are on Windows, the GNU windows tree.

ghostdog74
A: 

This is probably what you're looking for:

ls -R | tree

It's not installed by default on Ubuntu. So, to install it:

sudo apt-get install tree
George Marian
tree doesn't take input from `ls -R`. you can `echo hello | tree` and achieve the same effect.
動靜能量
Ah, yes. You are correct. =/
George Marian
A: 

Windows has a tree command:

C:\folder>tree . /F
Folder PATH listing for volume sys
Volume serial number is F275-CBCA
C:\FOLDER.
│   file01.txt
│
├───Sub folder
│       chart-0001.png
│       chart-0002.png
└───────chart-0004.png

The /F parameter is what tells it to show files. You can execute this from Powershell

JohnL