How can I print the file size and other file info in a Views field template? I have created a content type with a number of fields including file fields. In the node template for that CT (node--unit.html.twig) I am able to get the details with the following code:

{% if content.field_files.0 %}
   {% for key, value in content.field_files if key|first != '#' %}
      &lt;a href="{{ file_url(content.field_files[key]['#file'].uri.value) }}"&gt;{{ content.field_files[key]['#description']}}&lt;/a&gt;
   {% endfor %}
{% endif %}


Now I'm trying to get those same details for the field inside a view that lists nodes of that CT but the above code doesn't work. In fact all I can get from the field is the 'content' using the following code inside the views-view-field template (views-view-fields--units-e-resource-sheets.html.twig):

{{ fields.field_e_resources.content}}


All I can find using kint and other tools is the target_id attribute. Do I have to use this to retrieve those other details in the view?
Well with some pointers from colleagues I have found out what I was doing wrong!

In the node you have all that info already there but views and their displays are more stripped back to keep them 'lean' so you have to be explicit that you need that info...

Step 1 - add a 'relationship' to the field

In the settings for the display of the view, I added a relationship to the file from the field under the 'advanced' settings using the 'add' button and it shows like this:



Step 2 - add fields for the stuff from the relationship

Under the fields for the view display I can now add fields for the relationship I just created. I added one for the URI and one for the filesize using the 'add' button and they show like this:



Step 3 - build the template

Now you can use those just like any regular field in the template. Here is the code I'm using to build a link with the file extension, filesize and a link to download the file:

&lt;a href="{{ file_url(fields.uri.content|striptags|trim|convert_encoding('UTF-8', 'HTML-ENTITIES')) }}" target="_blank"&gt;Download
  (.{{ fields.field_e_resources.content|striptags|split('.')[1] }})({{ fields.filesize.content }})
&lt;/a&gt;


Conclusion

I couldn't access the details for the uploaded file because they aren't included by default so by building the relationships as required you can add to the available fields and get the job done!