Rev 39 | Rev 41 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#! /usr/bin/env elixir
# https://rosettacode.org/wiki/Walk_a_directory/Recursively
# TODO : de hele traversal nog schrijven, dit is alleen argument parsing
# =============================================================================
# Create
# name : Andre Rikkert de Koe date: mar 2018
# descr : filefind
# This is a demo of programming in the elixir 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
# =============================================================================
defmodule DezeModule do
def usage(progname, mesg) do
IO.puts "Usage: " <> progname <> " filefind"
IO.puts mesg
end
def traverse(directory) do
File.cd!(directory)
curdir2 = System.cwd()
files = File.ls!(directory)
for file <- files do
pfile = curdir2 <> "/" <> file
IO.puts pfile
if File.dir?(pfile) do
traverse(pfile)
end
end
end
def start_traverse(directory) do
IO.puts directory
traverse(directory)
end
end
# =============================================================================
# Main
# =============================================================================
#
progname = System.cwd()
if length(System.argv) == 1 do
directory = Enum.at(System.argv(), 0)
if File.dir?(directory)
do
DezeModule.start_traverse(directory)
else
DezeModule.usage(progname, "ERROR: Not a directory : " <> directory)
end
else
DezeModule.usage(progname, "ERROR: 1 argument expected")
end