Returning a filename

I am using Linux 4.2 on a Dell. GNU gcc compiler.

I have a directory full of files named as follows:


I am writing a function
std::string function return_fname(int cmd_id)

where an integer cmd_id is passed in for example 003

I need to parse through a directory of filenames looking for the filename that starts with 003, and return it.

I have no idea where to begin to ID the individual filenames in the list, capture the filename. Is there a built in function that will do this, is it a stream function, a string function, as you can see the filenames are all structured differently except that the first 3 characters is a 3 digit number and the extension is .dat Each file has a unique first 3 characters.


scandir can tell you all the file names in a a directory. You can then filter out the ones that begin with your ID.

A description of scandir is at:

A quick search on the web can show examples of using scandir.
Thank You, that looks like it fits the need.
Topic archived. No new replies allowed.