Subversion Repositories svn.Prod repos

Rev

Rev 4 | Rev 37 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 ls 1
#!/usr/bin/env bash 
4 ls 2
# =============================================================================
3
# Create
4
# name  : Andre Rikkert de Koe          date:   apr 2011
5
# descr : filefind
6
#         This is a demo of programming in the bash language.
7
#         Its part of a project to implement a program to create a directory
8
#         tree similar to the output of the Unix find program.
9
# EUID  : Any user who has read access to all the files being searched for.
10
# run   : interactive
11
#
12
# Changes
13
# name  :                               date:
14
# descr : short description
15
#
16
# =============================================================================
3 ls 17
 
18
# =============================================================================
19
# Functions
20
# =============================================================================
21
 
22
Usage()
23
{
24
	mesg="$1"
25
 
26
	echo "Usage : $progname directory"
27
	echo $mesg
28
}
29
 
30
#
31
# we need local vars to keep the value when called recursively
32
#
33
traverse()
34
{
35
	local directory="$1"
36
 
37
	local curdir curdir2
38
 
39
	curdir=$(pwd)
40
	cd -- "$directory"
41
	curdir2=$(pwd)
33 - 42
	files=$(ls -a)
3 ls 43
	for file in $files 
44
	do
45
		pfile=$curdir2/$file	# file including path
33 - 46
		if [ $file != ".." -a $file != "." ]
3 ls 47
		then
33 - 48
			if [ -d "$file" -a ! -L "$file" ]
3 ls 49
			then
33 - 50
				echo $pfile
51
				traverse "$file"
3 ls 52
			else
33 - 53
				if [ -f $file -o -L $file ]
54
				then
55
					echo "$pfile"
56
				else
57
					echo "WARNING: Could not process file $pfile"
58
				fi
3 ls 59
			fi
33 - 60
 
3 ls 61
		fi	
62
	done
63
	cd -- "$curdir"
64
}
65
 
66
start_traverse()
67
{
68
	directory=$1
69
 
70
	echo $directory
71
	traverse $directory
72
}
73
 
74
# =============================================================================
75
# MAIN
76
# =============================================================================
77
 
78
progname=$(basename $0)
79
if [ $# -eq 1 ]
80
then
81
	directory=$1
82
	if [ -d $directory ]
83
	then 
84
		start_traverse $directory
85
	else
86
		Usage "ERROR: No directory $directory found"
87
	fi
88
else
89
	Usage "ERRROR: 1 argument expected"
90
fi