Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. defmodule Directory do
  2.  
  3. def flatten(path, destiny) do
  4. {:ok, files} = File.ls(path)
  5. Enum.map(files, fn(file) ->
  6. new_path = path <> "/" <> file
  7. if File.dir?(new_path) do
  8. flatten(new_path, destiny)
  9. else
  10. # Filesystem is disabled, so there is no copy function,
  11. # instead we will just print out our directories
  12. # File.copy(new_path, destiny <> "/" <> file)
  13. IO.puts "copy file from: #{new_path}"
  14. IO.puts "copy file to: #{destiny}/#{file}\n"
  15. end
  16. end)
  17. end
  18.  
  19. end
  20.  
  21. # No files system so:
  22. # * "elixir/lib/logger" is the directory which we intend to copy files from
  23. # * "fake_dir" is the fake directory which we intend to copy to
  24. Directory.flatten("elixir/lib/logger", "fake_dir")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement