LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to get the list of files with a certain extension in a folder ? (https://www.linuxquestions.org/questions/programming-9/how-to-get-the-list-of-files-with-a-certain-extension-in-a-folder-752325/)

aryan1 09-03-2009 03:42 AM

how to get the list of files with a certain extension in a folder ?
 
Hi All,

Is there any C/C++ API in Linux that I can use to get the names of the files in a folder with a certain extension ?

I came across readdir() and scandir() functions.

readdir() gives the list of all files - it does not seem to be providing any filtering option.

scandir() provides some filtering options, but I could not understand if it is capable of giving me the names of the files with a certain extension.

I just want to avoid extra string processing in my application, but have C/C++ API perform that instead.

Any ideas ?

Thanks.

neonsignal 09-03-2009 10:14 AM

The scandir filtering option is merely a function that you provide to the scandir. You can write your own function to test for the extension (but obviously this requires a string comparison).

XavierP 09-03-2009 02:12 PM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 02:09 PM.