开发者

Can PowerShell (or script) on Windows / Mac / Ubuntu list file / directory structure easily?

开发者 https://www.devze.com 2023-01-04 17:05 出处:网络
Can PowerShell on Windows by itself or using simple shell script, list files and director开发者_StackOverflowy this way:(or using Mac OS X or Ubuntu\'s shell script)

Can PowerShell on Windows by itself or using simple shell script, list files and director开发者_StackOverflowy 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.


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.


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


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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消