Alternatively this should also work
There is no real reason why the variable name needs to bear any relationship to the value.
char *ext = "mid";
could have become
char *ext = "csv"';
with no need to change the rest of the code, to list files with different extensions.