| Line | |
|---|
| 1 | #!/bin/ksh
|
|---|
| 2 | #
|
|---|
| 3 | # Name: dirtree
|
|---|
| 4 | # Programmer:
|
|---|
| 5 | # Hemant T. Shah
|
|---|
| 6 | # Life Insurance Data Processing
|
|---|
| 7 | # July 12 1994
|
|---|
| 8 | #
|
|---|
| 9 | # Description:
|
|---|
| 10 | # Print directory tree structure as follows:
|
|---|
| 11 | # |___Mail
|
|---|
| 12 | # |___scheduler
|
|---|
| 13 | # |___cics_scripts
|
|---|
| 14 | # |___tar_msdos
|
|---|
| 15 | # |___awk
|
|---|
| 16 | # |___attributes
|
|---|
| 17 | # |___tmp
|
|---|
| 18 | # |___News
|
|---|
| 19 | # |___dosscsi
|
|---|
| 20 | # |___FAQ_xterminal
|
|---|
| 21 | # |___shell_history.Z
|
|---|
| 22 | # |___FAQ_AIX
|
|---|
| 23 | # |___aix_ftp_site
|
|---|
| 24 | # |___hp_software
|
|---|
| 25 | # |___dnload
|
|---|
| 26 | # |___telnet.h
|
|---|
| 27 | # |___msdos
|
|---|
| 28 | # |___tnetd.tar.Z
|
|---|
| 29 | # |___aix
|
|---|
| 30 | # |___hp
|
|---|
| 31 | # |___xkey.c
|
|---|
| 32 | #
|
|---|
| 33 | # Conversion to bash v2 syntax done by Chet Ramey
|
|---|
| 34 | # - removed command substitutions calling `basename'
|
|---|
| 35 | #
|
|---|
| 36 |
|
|---|
| 37 | ProgramName=${0##*/}
|
|---|
| 38 | Path="."
|
|---|
| 39 | ShowAll=1
|
|---|
| 40 | ShowDir=0
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | ExpandDirectory()
|
|---|
| 44 | {
|
|---|
| 45 | local object # Local variable
|
|---|
| 46 |
|
|---|
| 47 | cd "$1"
|
|---|
| 48 |
|
|---|
| 49 | for object in $PWD/.??* $PWD/*
|
|---|
| 50 | do
|
|---|
| 51 | if [ -d $object ]; # It is a directory
|
|---|
| 52 | then
|
|---|
| 53 | echo "${indent}|___${object##*/}/"
|
|---|
| 54 | indent="${indent}! " # Add to indentation
|
|---|
| 55 | if [ -x $object ];
|
|---|
| 56 | then
|
|---|
| 57 | ExpandDirectory $object
|
|---|
| 58 | fi
|
|---|
| 59 | indent=${indent%????} # Remove from indentation
|
|---|
| 60 | elif [ -e $object ]; then
|
|---|
| 61 | if (( ShowAll == 1 ));
|
|---|
| 62 | then
|
|---|
| 63 | echo "${indent}|___${object##*/}"
|
|---|
| 64 | fi
|
|---|
| 65 | fi
|
|---|
| 66 | done
|
|---|
| 67 |
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | usage()
|
|---|
| 71 | {
|
|---|
| 72 | echo -e "Usage: $ProgramName [-h] [-f] [-d] [path] "
|
|---|
| 73 | echo -e "\t-h ... display this help message."
|
|---|
| 74 | echo -e "\t-f path ... shows all files and directories below path (default)."
|
|---|
| 75 | echo -e "\t-d path ... shows all directories only below path."
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | while getopts "fd" opt
|
|---|
| 79 | do
|
|---|
| 80 | case $opt in
|
|---|
| 81 | f) ShowAll=1 ;;
|
|---|
| 82 | d) ShowDir=1 ;;
|
|---|
| 83 | *) usage ; exit 2;;
|
|---|
| 84 | esac
|
|---|
| 85 | done
|
|---|
| 86 |
|
|---|
| 87 | shift $(( $OPTIND - 1 ))
|
|---|
| 88 |
|
|---|
| 89 | Path=${1:-.}
|
|---|
| 90 |
|
|---|
| 91 | if [ ! -d "$Path" ]; then
|
|---|
| 92 | echo "$0: error: specified path is not a directory." >&2
|
|---|
| 93 | exit 1
|
|---|
| 94 | fi
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | echo "!$Path/"
|
|---|
| 99 | ExpandDirectory $Path
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.