LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2009, 03:42 AM   #1
aryan1
Member
 
Registered: Jul 2009
Posts: 50

Rep: Reputation: 16
Question 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.
 
Old 09-03-2009, 10:14 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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).
 
Old 09-03-2009, 02:12 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need bash script to list files, drop extension and dump to file talwar_ Programming 10 06-03-2011 09:18 AM
copying folder and changing extension of files in it? stratotak Linux - Newbie 18 03-10-2009 01:16 AM
List files that don't have a certain extension swatward Linux - Newbie 5 09-09-2007 02:02 PM
Display a list of files in a folder in apache Snorideguy Linux - Software 4 02-26-2004 01:05 PM
I have 8 character file name, no extension files being created in my dbaseIII+ folder bonzo Linux - General 2 01-22-2004 06:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration