/ruby/filefind.rb |
---|
File deleted |
Property changes: |
Deleted: svn:executable |
-* |
\ No newline at end of property |
/ruby/result |
---|
File deleted |
/filefind/python/filefind.py |
---|
0,0 → 1,46 |
#! /usr/bin/env python3.1 |
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: No directory " + directory + " found") |
else: |
Usage("ERROR: 1 argument expected") |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/filefind/python/Makefile |
---|
0,0 → 1,15 |
DIR = /home/arikkert |
test: filefind.py |
./filefind.py $(DIR) > result |
sort result > result.sort |
find $(DIR) > result2 |
sort result2 > result2.sort |
wc *.sort |
diff *.sort |
clean: |
rm -f filefind |
rm -rf result result.sort |
rm -rf result2 result2.sort |
/filefind/ruby/filefind.rb |
---|
0,0 → 1,71 |
#!/usr/bin/env ruby19 |
# ============================================================================= |
# Create |
# name : Andre Rikkert de Koe date: apr 2011 |
# descr : filefind |
# This is a demo of programming in the ruby 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 |
# |
# ============================================================================= |
# ============================================================================= |
# Functions |
# ============================================================================= |
def Usage(progname, mesg) |
puts "Usage : #{progname} directory" |
puts mesg |
end |
# |
# dir is directory to traverse |
# |
def traverse(dir) |
curdir = Dir.getwd |
Dir.chdir(dir) |
curdir2 = Dir.getwd |
Dir.foreach(Dir.getwd) { | file | |
pfile = curdir2 + "/" +file |
if File.directory?(file) && !File.symlink?(file) |
if (file != "..") && (file != ".") |
puts pfile |
traverse(file) |
end |
else |
if File.file?(file) || File.symlink?(file) |
puts "#{pfile}" |
else |
puts "WARNING: Could not process file $pfile" |
end |
end |
} |
Dir.chdir(curdir) |
end |
def start_traverse(directory) |
puts directory |
traverse(directory) |
end |
# ============================================================================= |
# MAIN |
# ============================================================================= |
progname = File.basename($0) |
if (ARGV.length == 1) |
directory = ARGV[0] |
if File.directory?(directory) |
start_traverse(directory) |
else |
Usage progname, "ERROR: No directory #{directory} found" |
end |
else |
Usage progname, "ERROR: 1 argument expected" |
end |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/filefind/ruby/Makefile |
---|
0,0 → 1,15 |
DIR = /home/arikkert |
test: filefind.rb |
./filefind.rb $(DIR) > result |
sort result > result.sort |
find $(DIR) > result2 |
sort result2 > result2.sort |
wc *.sort |
diff *.sort |
clean: |
rm -f filefind |
rm -rf result result.sort |
rm -rf result2 result2.sort |
/filefind/C/filefind.c |
---|
0,0 → 1,127 |
/* ============================================================================ |
# Create |
# name : Andre Rikkert de Koe date: apr 2011 |
# descr : filefind |
# This is a demo of programming in the C 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 |
# |
============================================================================ */ |
#include <stdio.h> |
#include <libgen.h> |
#include "checkfiles.h" |
#include <unistd.h> // getcwd |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <dirent.h> |
#include <unistd.h> |
#include <errno.h> |
#define PATH_MAX 255 |
// ============================================================================ |
// Functions |
// ============================================================================ |
void Usage(char *progname, char *mesg) |
{ |
printf("Usage: %s directory\n" ,progname); |
printf("%s\n", mesg); |
} |
// http://www.ibm.com/developerworks/aix/library/au-unix-readdir.html |
void traverse(char *directory) |
{ |
char curdir[PATH_MAX]; |
char curdir2[PATH_MAX]; |
getcwd(curdir, PATH_MAX); |
chdir(directory); |
getcwd(curdir2, PATH_MAX); |
DIR *dir = NULL; |
struct dirent entry; |
struct dirent *entryPtr = NULL; |
int retval = 0; |
char pathName[PATH_MAX + 1]; |
char pfile[PATH_MAX + 1]; |
/* Open the given directory, if you can. */ |
dir = opendir(curdir2); |
if (dir == NULL) |
{ |
printf( "Error opening %s: %s", directory, strerror( errno ) ); |
} |
retval = readdir_r( dir, &entry, &entryPtr ); |
while( entryPtr != NULL ) |
{ |
struct stat entryInfo; |
if( ( ! strncmp( entry.d_name, ".", PATH_MAX ) == 0 ) && |
( ! strncmp( entry.d_name, "..", PATH_MAX ) == 0 ) ) |
{ |
sprintf(pfile,"%s/%s", curdir2, entry.d_name); |
if (isdir(entry.d_name) && ! issymlink(entry.d_name)) |
{ |
printf("%s\n", pfile); |
traverse(entry.d_name); |
} |
else |
{ |
if ((isregular(entry.d_name)) || issymlink(entry.d_name)) |
printf("%s\n", pfile); |
else |
printf("WARRNING: Could not process file %s\n", entry.d_name); |
} |
} |
retval = readdir_r( dir, &entry, &entryPtr ); |
} |
chdir(curdir); |
} |
void start_traverse(char *directory) |
{ |
printf("%s\n", directory); |
traverse(directory); |
} |
// ============================================================================ |
// MAIN |
// ============================================================================ |
main(int argc, char *argv[]) |
{ |
char *progname = argv[0]; |
char *directory; |
char mesg[80]; |
progname = basename(progname); |
if (argc == 2) |
{ |
directory = argv[1]; |
if (isdir(directory)) |
{ |
start_traverse(directory); |
} |
else |
{ |
sprintf(mesg, "ERROR: No directory %s found", directory); |
Usage(progname, mesg); |
} |
} |
else |
{ |
Usage(progname, "ERROR : 1 argument expected"); |
} |
} |
/filefind/C/checkfiles.h |
---|
0,0 → 1,30 |
#include <stdio.h> |
#include <sys/stat.h> |
// ============================================================================ |
// Functions |
// ============================================================================ |
// functions return 1 if true |
int testfile(char *file, unsigned type) |
{ |
int returnvalue; |
struct stat buf; |
if (lstat (file, &buf) == 0) |
{ |
// its a file, test if a synlink |
returnvalue = (( buf.st_mode & S_IFMT) == type); |
} |
else |
{ |
// its not even a file |
returnvalue = 0; |
} |
return returnvalue; |
} |
int isregular(char *file) { return testfile(file, S_IFREG); } |
int issymlink(char *file) { return testfile(file, S_IFLNK); } |
int isdir(char *file) { return testfile(file, S_IFDIR); } |
/filefind/C/Makefile |
---|
0,0 → 1,16 |
filefind: checkfiles.h filefind.c |
$(CC) $@.c -o $@ |
test: filefind |
./filefind /home/arikkert > result |
sort result > result.sort |
find /home/arikkert > result2 |
sort result2 > result2.sort |
wc *.sort |
diff *.sort |
clean: |
rm -f filefind |
rm -rf result result.sort |
rm -rf result2 result2.sort |