[go: up one dir, main page]

Menu

[r217]: / bin / recurse  Maximize  Restore  History

Download this file

76 lines (65 with data), 1.2 kB

#!/bin/sh
## shfunction for ctafconf in /home/ctaf/.ctafconf
##
## Made by GESTES Cedric
## Login   <ctaf42@gmail.com>
##
## Started on  Sun Oct  2 07:23:17 2005 GESTES Cedric
## Last update Wed Nov 21 10:04:44 2007 GESTES Cedric
##
##CTAFCONF


action="$1"
dir="$2"

#display all file and folder recursively
recurse ()
{
  local arg="$1"
  local i=""
  local fn=""

  ls $arg 2>/dev/null | while read i; do
    fn=$arg/$i
    if [ -d $fn ]; then
      echo "$fn";
      recurse $fn;
    elif [ -f $fn ]; then
      echo "$fn";
    fi;
  done;
}

recurse_file ()
{
  local arg="$1"
  local i=""
  local fn=""

  ls $arg 2>/dev/null | while read i; do
    fn=$arg/$i
    if [ -d $fn ]; then
      recurse_file $fn;
    elif [ -f $fn ]; then
      echo "$fn";
    fi;
  done;
}

recurse_folder ()
{
  local arg="$1"
  local i=""
  local fn=""

  ls $arg 2>/dev/null | while read i; do
    fn=$arg/$i
    if [ -d $fn ]; then
      echo "$fn";
      recurse_folder $fn;
    fi;
  done;
}


if [ x$action = xfile ]; then
  recurse_file $dir;
elif [ x$action = xfolder ]; then
  recurse_folder $dir;
elif [ x$action = xboth ]; then
  recurse $dir;
else
  echo "usage: recurse type directory"
  echo "type could be: file or folder or both"
fi