# Creating files with information

**URL:** <https://forum.elixirforum.com/t/creating-files-with-information/33918>\
**Category:** Questions\
**Tags:** file\
**Created:** [August 22, 2020, 10:34pm UTC](https://forum.elixirforum.com/t/creating-files-with-information/33918 "2020-08-22T22:34:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertosj](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gilbertosj](https://forum.elixirforum.com/u/gilbertosj)\
**Post date:** [August 22, 2020, 10:34pm UTC](https://forum.elixirforum.com/t/creating-files-with-information/33918/1 "2020-08-22T22:34:36Z")

</div>

I have a little doubt,

how do you go about creating and writing a file in the elixir?

Ex:

I intend to create a file with the following information below

my\_file.conf

> !## My configuration file  
> Name: test example  
> Number: 6299999  
> Ip: 127.0.0.1
> 
> Note: Value $ 10000

Note that there are spaces and line breaks.  
This my\_file.conf file, will need to be created in a specific folder (/var/log/myfile.conf)

I intend that the application itself creates this file.

How do you do that?  
Do you use any dependencies for that?

---

<div class="post-metadata">

**Author:** ![kokolegorille](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kokolegorille/32/4784_2.png) [@kokolegorille](https://forum.elixirforum.com/u/kokolegorille)\
**Post date:** [August 22, 2020, 11:21pm UTC](https://forum.elixirforum.com/t/creating-files-with-information/33918/2 "2020-08-22T23:21:19Z")

</div>

You can use the [File module](https://hexdocs.pm/elixir/File.html) to do that.

It has read and write functions…

---

<div class="post-metadata">

**Author:** ![gilbertosj](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gilbertosj](https://forum.elixirforum.com/u/gilbertosj)\
**Post date:** [August 22, 2020, 11:35pm UTC](https://forum.elixirforum.com/t/creating-files-with-information/33918/3 "2020-08-22T23:35:58Z")

</div>

I was thinking of using System.cmd, running an “echo ‘’ \> my\_file.txt”, but I didn’t like this solution.

I will read more about what you told me.  
Thank you

---

<div class="post-metadata">

**Author:** ![pdgonzalez872](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pdgonzalez872/32/28792_2.png) [@pdgonzalez872](https://forum.elixirforum.com/u/pdgonzalez872)\
**Post date:** [August 23, 2020, 10:04pm UTC](https://forum.elixirforum.com/t/creating-files-with-information/33918/4 "2020-08-23T22:04:52Z")

</div>

Hi @gilbertosj, here is an iex session that may help you:

```elixir
iex(1)> string = """
...(1)> Hi, gilbertosj! That's a great question.
...(1)> You can use EEx (https://github.com/elixir-lang/elixir/tree/master/lib/eex)
...(1)> EEx is part of the standard library and can help you with your task. 
...(1)> EEx + the File module (as stated above) would solve your problem.
...(1)> Here is an example of a variable: <%= variable %>
...(1)> Here is a lesson about this on ElixirSchool: https://elixirschool.com/en/lessons/specifics/eex 
...(1)> Hope this helps!   
...(1)> """
"Hi, gilbertosj! That's a great question.\nYou can use EEx (https://github.com/elixir-lang/elixir/tree/master/lib/eex)\nEEx is part of the standard library and can help you with your task.\nEEx + the File module (as stated above) would solve your problem.\nHere is an example of a variable: <%= variable %>\nHere is a lesson about this on ElixirSchool: https://elixirschool.com/en/lessons/specifics/eex\nHope this helps!\n"
iex(2)> content = EEx.eval_string(string, [variable: "EXAMPLE VARIABLE"])       
"Hi, gilbertosj! That's a great question.\nYou can use EEx (https://github.com/elixir-lang/elixir/tree/master/lib/eex)\nEEx is part of the standard library and can help you with your task.\nEEx + the File module (as stated above) would solve your problem.\nHere is an example of a variable: EXAMPLE VARIABLE\nHere is a lesson about this on ElixirSchool: https://elixirschool.com/en/lessons/specifics/eex\nHope this helps!\n"
iex(3)> File.write!("this_is_a_filename.txt", content)
:ok

```

Now, you can check the file we just created:

```elixir
pdg :> cat this_is_a_filename.txt 
Hi, gilbertosj! That's a great question.
You can use EEx (https://github.com/elixir-lang/elixir/tree/master/lib/eex)
EEx is part of the standard library and can help you with your task.
EEx + the File module (as stated above) would solve your problem.
Here is an example of a variable: EXAMPLE VARIABLE
Here is a lesson about this on ElixirSchool: https://elixirschool.com/en/lessons/specifics/eex
Hope this helps!

```
