0,0 → 1,81 |
<?php |
# ============================================================================= |
# Create |
# name : Andre Rikkert de Koe date: apr 2011 |
# descr : filefind |
# This is a demo of programming in the PHP language (CLI). |
# 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 |
# |
# ============================================================================= |
|
# ============================================================================= |
# Functions |
# ============================================================================= |
|
function Usage($mesg, $progname) |
{ |
echo "Usage : $progname\n"; |
echo "$mesg\n"; |
} |
|
function traverse($dir) |
{ |
$curdir = getcwd(); |
chdir($dir); |
$curdir2 = getcwd(); |
$myDirectory = opendir("."); |
# http://php.net/manual/fr/function.readdir.php |
while (false !== ($file = readdir($myDirectory))) |
{ |
$pfile = $curdir2 . "/" . $file; |
if (is_dir($file) && !is_link($file)) |
{ |
if ($file != ".." && $file != ".") |
{ |
echo "$pfile\n"; |
traverse($file); |
} |
} |
else |
{ |
if (is_file($file) || is_link($file)) |
echo "$pfile\n"; |
else |
echo "WARNING: Could not process file $pfile\n"; |
} |
} |
chdir($curdir); |
|
} |
|
function start_traverse($directory) |
{ |
echo "$directory\n"; |
traverse($directory); |
} |
|
# ============================================================================= |
# MAIN |
# ============================================================================= |
|
$progname = $argv[0]; |
|
if ( $argc == 2 ) |
{ |
$directory = $argv[1]; |
if (is_dir($directory)) |
start_traverse($directory); |
else |
Usage($progname, "ERROR: No directory $directory found"); |
} |
else |
Usage($progname, "ERROR: 1 argument expected"); |
|
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |