Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi guys. I'd like to know if there's a way to handle several files even if I know only the directory where they are located. I should operate on them in the same way for each one, but since they are more than 30, I should need to open them without knowing their names.
Posted
Comments
Sergey Alexandrovich Kryukov 16-May-14 16:58pm    
It depends on the platform. You need to ask the OS what files are in some directory.
—SA
militandri 16-May-14 17:25pm    
Sorry, I forgot to write it... I'm on Windows.
Sergey Alexandrovich Kryukov 16-May-14 18:39pm    
Thank you for this clarification, which was actually important. I answered. The question posting problem looks fixed now; so you can see it as Solution 1.
—SA

1 solution

 
Share this answer
 
Comments
militandri 17-May-14 12:39pm    
I read something about the dirent.h header file containing some intresting functions... But I didn't understand how to read so many file names if the d_name variable in dirent structure is just a string and not an array of strings...
Sergey Alexandrovich Kryukov 20-May-14 23:26pm    
You did not, by you certainly should see how to do it after reading this documentation.
Will you accept the answer formally (green "Accept" button)? In all cases, your follow-up questions will be welcome.
—SA
[no name] 20-May-14 11:58am    
"dirent" structure can not be used like that. That's wrong.

Are you strict about using only C? Why not C++?
If you switch to C++, you can use some libraries such as POCO. Check Filesystem in POCO C++ libraries. It has a class called DirectoryIterator which may be helpful. You can consider that particularly if you're inconvenient with the Win32 API.
Click here to go to POCO documentation
Check whether the library is useful to you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900