You'd have to pass the list of files in the desired directory through a function that tests whether their filename (a string of characters, e.g. "myFileName.txt") contains a sub-string of characters that you specify (following your example, ".txt". To make your filetype filter more specific you'd also have to ascertain that ".txt" constitutes the last characters in the given filename, otherwise the filter will return files with ".txt" within
the filename but not necessarilly defining filetype, e.g. "myImageFileName.txt.jpg").
For any given filename, if the sub-string you specify is not contained in it, the file entry would be removed from your file list, until only the ones that contain ".txt" will remain (So you will have succesfully applied the filter / "mask" to the files).
To apply something like this, you'd need to go through the string representing (every one of) your file's names, and look for the first character of your substring (in this example, "."). Once a "." is found, then the next character in the filename would have to match the next character in your sub-string ("t"). If not, then the filter is reset and always starts looking from the first element (here, "."). Something like this:
string fileName = ("myFileName.txt");
string subString = (".txt");
int subStringCounter = 0; //used to iterate through each character of the sub-string
bool fileNameContainsSubString = false;
for(int i=0; i<fileName.size() ; i++)
fileNameContainsSubString = true;
if(!fileNameContainsSubString) //if the file doesn't contain the sub-string specified by the filter
//remove file from your list, so that only the ones containing the sub-string will remain
EDIT: sorry, I wrote the code using char arrays and then changed it to std::strings but hadn't added std::string::compare in the "if" condition of line 8.