Compare Identical Files

From ElixirBlocks
Jump to: navigation, search
defmodule FileComparator do
  def compare(file1, file2) do
    IO.inspect File.cwd!()
    content1 = read_file(file1)
    content2 = read_file(file2)

    if content1 == content2 do
      IO.puts("The files have identical content.")
    else
      IO.puts("The files have different content.")
    end
  end

  defp read_file(file_path) do
    case File.read(file_path) do
      {:ok, content} -> content
      {:error, reason} -> raise "Failed to read #{file_path}: #{reason}"
    end
  end
end

FileComparator.compare("c:/Users/william.turner/Desktop/sandbox/app/files/example.md", "c:/Users/william.turner/Desktop/sandbox/app/files/example_2.md" )