How do I create an array from a forloop?

You are almost there, the way of how you are creating the array it is the only thing to fix.

This {% assign my_array = "" %} creates an empty string. One easy way to create an array in Liquid is to split the above:

{% assign my_array = "" | split: ',' %}

Now you can push items into the array inside a for loop in the following way:

{% for image in site.static_files %}
  {% if image.path contains "assets/images/target-folder" %}
     <!-- Push image into array -->
     {% assign my_array = my_array | push: image %}
  {% endif %}
{% endfor %}

Also note that you can do this without a loop using where/where_exp filters:

  {% assign my_array = site.static_files | 
      where_exp: "item", "item.path contains 'assets/images/target-folder'" %}

or:

  {% assign target_folder = "assets/images/target-folder" %}
  {% assign my_array = site.static_files | 
      where_exp: "item", "item.path contains target_foler" %}

(Although, unlike the accepted answer, this doesn't precisely correspond to the question's title, it's still a useful option in the described example.)