0,0 → 1,74 |
#!/usr/bin/env bash |
# progname : filefind.bash |
# purpose : display a directory tree |
# similar to find |
|
# ============================================================================= |
# Functions |
# ============================================================================= |
|
Usage() |
{ |
mesg="$1" |
|
echo "Usage : $progname directory" |
echo $mesg |
} |
|
# |
# we need local vars to keep the value when called recursively |
# |
traverse() |
{ |
local directory="$1" |
|
local curdir curdir2 |
|
curdir=$(pwd) |
cd -- "$directory" |
curdir2=$(pwd) |
files=$(ls) |
for file in $files |
do |
pfile=$curdir2/$file # file including path |
if [ -d "$file" -a ! -L "$file" ] |
then |
echo $pfile |
traverse "$file" |
else |
if [ -f $file -o -L $file ] |
then |
echo "$pfile" |
else |
echo "WARNING: Could not process file $pfile" |
fi |
fi |
done |
cd -- "$curdir" |
} |
|
start_traverse() |
{ |
directory=$1 |
|
echo $directory |
traverse $directory |
} |
|
# ============================================================================= |
# MAIN |
# ============================================================================= |
|
progname=$(basename $0) |
if [ $# -eq 1 ] |
then |
directory=$1 |
if [ -d $directory ] |
then |
start_traverse $directory |
else |
Usage "ERROR: No directory $directory found" |
fi |
else |
Usage "ERRROR: 1 argument expected" |
fi |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |