Subversion Repositories svn.Prod repos

Rev

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

Rev Author Line No. Line
40 - 1
#! /usr/bin/env elixir
39 - 2
# https://rosettacode.org/wiki/Walk_a_directory/Recursively
3
 
40 - 4
# =============================================================================
5
# Create
6
# name  : Andre Rikkert de Koe          date:	mar 2018 
7
# descr : filefind
8
#         This is a demo of programming in the elixir language.
9
#         Its part of a project to implement a program to create a directory
10
#         tree similar to the output of the Unix find program.
11
# EUID  : Any user who has read access to all the files being searched for.
12
# run   : interactive
13
#
14
# Changes
15
# name  :                               date:
16
# descr : short description
17
#
18
# =============================================================================
19
 
20
# =============================================================================
21
# Functions
22
# =============================================================================
23
 
39 - 24
defmodule DezeModule do
25
 
26
	def usage(progname, mesg) do
27
		IO.puts "Usage: " <> progname <> " filefind" 
28
		IO.puts mesg	
29
	end
30
 
40 - 31
	def traverse(directory) do
32
		File.cd!(directory)
33
		curdir2 = System.cwd()
34
		files = File.ls!(directory)
35
		for file <- files do
36
			pfile = curdir2 <> "/" <> file
37
			IO.puts pfile
38
			if File.dir?(pfile) do
39
				traverse(pfile)
40
			end
41
		end
42
	end
43
 
44
	def start_traverse(directory) do
45
		IO.puts directory
46
		traverse(directory)
47
	end
39 - 48
end
49
 
40 - 50
# =============================================================================
51
# Main
52
# =============================================================================
53
#
39 - 54
progname = System.cwd()
55
 
56
if length(System.argv) == 1 do
57
	directory = Enum.at(System.argv(), 0)
58
	if File.dir?(directory)
59
	do
40 - 60
		DezeModule.start_traverse(directory)
39 - 61
	else
62
		DezeModule.usage(progname, "ERROR: Not a directory : " <> directory)
63
	end
64
else
65
	DezeModule.usage(progname, "ERROR: 1 argument expected")
66
end