What method (or a library function) do we use in C or C++ to read the file index ( i.e., the list of all the files) in a directory.
My motive is to create a function to make an extended search possible in a directory (or a file system) by reading the list of files in a directory. Since we don't already know what files are existing on the disk we cannot open and read them.
However, I know that programs like 'ls' and 'dir' in Unix/Linux are able to read the contents of a directory; since these OS are also written mostly in C, there must be some way to create a similar function under one program.
Following is the algorithm that I want to use:
- Take input from the user to navigate to a directory on the file system
- Read the contents of the file
- Make a linked list and add to it the contents of the directory that we just read
- Use the linked list to read the file name and one by one search through file contents using an existing algorithm
- Writing the output to the screen explaining the results found (results are indexed in an order or priority decided by an existing algorithm).
I have coded the algorithms used in step 4 and 5, and can do the step 1 and 3 on my own. The only problem that I'm having is with step 2. Is there any librairy in C/C++ or any other method by which we can achive the solution to this problem?
Thank you!