Rev 42 | 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 |
||
43 | - | 6 | # name : Andre Rikkert de Koe date: Mar 2018 |
40 | - | 7 | # descr : filefind |
43 | - | 8 | # This is a demo of programming in the Elixir language. |
40 | - | 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 |
42 | - | 32 | curdir = System.cwd() |
40 | - | 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 |
||
42 | - | 43 | File.cd!(curdir) |
40 | - | 44 | end |
45 | |||
46 | def start_traverse(directory) do |
||
47 | IO.puts directory |
||
48 | traverse(directory) |
||
49 | end |
||
39 | - | 50 | end |
51 | |||
40 | - | 52 | # ============================================================================= |
53 | # Main |
||
54 | # ============================================================================= |
||
42 | - | 55 | |
39 | - | 56 | progname = System.cwd() |
57 | if length(System.argv) == 1 do |
||
58 | directory = Enum.at(System.argv(), 0) |
||
59 | if File.dir?(directory) |
||
60 | do |
||
40 | - | 61 | DezeModule.start_traverse(directory) |
39 | - | 62 | else |
63 | DezeModule.usage(progname, "ERROR: Not a directory : " <> directory) |
||
64 | end |
||
65 | else |
||
66 | DezeModule.usage(progname, "ERROR: 1 argument expected") |
||
67 | end |