How to filter filenames in views based on a match to currently logged username? I am quite novice to Drupal. I am trying to figure out how to create views listing files such that only those files are listed where filename contains currently logged username?
If you could use tokens in views filters you could do something like File: name ... contains any word ... [user:name] and that would end up in the sql as file_managed.filename LIKE '%username%' which would be cool. But you can't do that, to my knowledge.

You might achieve what you want using contextual filters having PHP code in both contextual filter and validator, maybe.

That said, depending on how much files and users you have and so on, it might be easier to tag the files with taxonomy terms. That way user wanting to change their username, eg. when they get married, won't brake your system. Also usernames having spaces, underscores, apostrophies etc. wouldn't be an issue.

Edit:

What do you know, this can be done with contextual filters! I don't know how practical or robust or performant this is but here goes:

1) Add a contextual filter of Global: null.
2) Provide some default value, doesn't matter what. For example Fixed value -> 'blaa'.
3) Specify validation criteria -> PHP code

global $user;

$view-&gt;query-&gt;where = array(
    1 =&gt; array(
        'conditions' =&gt; array(
            0 =&gt; array(
                'field' =&gt; 'file_managed.filename',
                'value' =&gt; '%' . $user-&gt;name . '%',
                'operator' =&gt; 'LIKE',
            )
        ),
        'args' =&gt; array(),
        'type' =&gt; 'AND',
    )
);
return true;


I figured this out with dpm($view). If you have other filters in the Filter criteria, this code will have to take that into account. Tampering with the $view like this is not really future proof, but theoretically possible.