Subversion Repositories svn.Prod repos

Rev

Rev 39 | Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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