# Can I generate yml files to the target folder in macro

**URL:** <https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104>\
**Category:** Help\
**Tags:** jinja, macro, macros\
**Created:** [July 12, 2023, 3:13am UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104 "2023-07-12T03:13:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeeplvnz](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jeeplvnz/32/2522_2.png) [@jeeplvnz](https://discourse.getdbt.com/u/jeeplvnz)\
**Post date:** [July 12, 2023, 3:13am UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/1 "2023-07-12T03:13:24Z")

</div>

## The problem I’m having

I want to generate yml files to the target folder in macro.

Is that possible?

Thank you.

---

<div class="post-metadata">

**Author:** ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)\
**Post date:** [July 12, 2023, 3:48am UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/2 "2023-07-12T03:48:26Z")

</div>

can you provide more dwtails.

---

<div class="post-metadata">

**Author:** ![jeeplvnz](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jeeplvnz/32/2522_2.png) [@jeeplvnz](https://discourse.getdbt.com/u/jeeplvnz)\
**Post date:** [July 12, 2023, 9:55pm UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/3 "2023-07-12T21:55:10Z")

</div>

@Surya Thank you for your reply.

For example, I create a macro like generate\_yaml\_for\_model.sql.

Then, I set a string variable like model\_yaml with the yaml content of a model.

Finally, I want to output the value of the variable to a physical file like model.yml to a subdirectory in the target folder.

In summary, I want to know if we can create/modify/delete folders and files in target folder from a macro.

Thank you.

---

<div class="post-metadata">

**Author:** ![jeeplvnz](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jeeplvnz/32/2522_2.png) [@jeeplvnz](https://discourse.getdbt.com/u/jeeplvnz)\
**Post date:** [July 15, 2023, 2:47am UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/4 "2023-07-15T02:47:44Z")

</div>

Looking for a reply.

---

<div class="post-metadata">

**Author:** ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)\
**Post date:** [July 15, 2023, 4:54pm UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/5 "2023-07-15T16:54:33Z")

</div>

I think its not possible with sql models but it migt be possible with dbt python models.  
dbt python models are py files u can write python code to read and write to files

---

<div class="post-metadata">

**Author:** ![jeeplvnz](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jeeplvnz/32/2522_2.png) [@jeeplvnz](https://discourse.getdbt.com/u/jeeplvnz)\
**Post date:** [July 15, 2023, 11:39pm UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/6 "2023-07-15T23:39:39Z")

</div>

Thank you, @Surya .

Can we create Macro by using Python (dbt python)?

Cheers.

---

<div class="post-metadata">

**Author:** ![jeeplvnz](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/jeeplvnz/32/2522_2.png) [@jeeplvnz](https://discourse.getdbt.com/u/jeeplvnz)\
**Post date:** [July 18, 2023, 8:54am UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/7 "2023-07-18T08:54:40Z")

</div>

Hi guys, any ideas?

Thank you.

---

<div class="post-metadata">

**Author:** ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)\
**Post date:** [July 18, 2023, 10:58am UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/8 "2023-07-18T10:58:37Z")

</div>

Creating files from macros is not possible  
But u can do onething create a python dbt model and write ur code there to generate yml file and run the model

I didn’t try this. U can give a try

---

<div class="post-metadata">

**Author:** ![RP\_007](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@RP\_007](https://discourse.getdbt.com/u/RP_007)\
**Post date:** [May 13, 2024, 3:48pm UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104/9 "2024-05-13T15:48:54Z")

</div>

you can try below  
dbt run-operation macroname --args ‘{a: b}’ \> ./myfile.yml  
it wont be a structured output but you can perform more operations on the string log saved in it
