#! /usr/bin/env python3
# =============================================================================
# Create
# name : Andre Rikkert de Koe date: Apr 2011
# descr : filefind
# This is a demo of programming in the Python language.
# Its part of a project to implement a program to create a directory
# tree similar to the output of the Unix find program.
# EUID : Any user who has read access to all the files being searched for.
# run : interactive
#
# Changes
# name : date:
# descr : short description
#
# =============================================================================
import sys
import os.path
# =============================================================================
# Functions
# =============================================================================
def Usage(mesg):
print ("Usage: " + progname + " directory")
print (mesg)
def traverse(directory):
curdir = os.getcwd()
os.chdir(directory)
curdir2 = os.getcwd()
files = os.listdir(curdir2)
for file in files:
pfile = curdir2 + "/" + file
if os.path.isdir(file) and not os.path.islink(file):
print (pfile)
traverse(file)
else:
if os.path.isfile(file) or os.path.islink(file):
print (pfile)
else:
print ("WARNING: Could not process file " + pfile)
os.chdir(curdir)
def start_traverse(directory):
print (directory)
traverse(directory)
# =============================================================================
# MAIN
# =============================================================================
progname = os.path.basename(sys.argv[0])
if (len(sys.argv) == 2):
directory = sys.argv[1]
if os.path.isdir(directory):
start_traverse(directory)
else:
Usage("ERROR: Not a directory : " + directory)
else:
Usage("ERROR: 1 argument expected")