Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C
Hi folks.
I hope to find some efficient code on Win32 to build a file list,when I choose a required directory/
I'd like to go through the all subdirectories to extract all files ( I mean a recursive function)
I think, that someone has faced that kind of task and could offer me the solution.
Thnx in advance.
Posted 22-Apr-12 9:49am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This can be done with Windows API FindFirstFile (FindFirstFileEx) / FindNextFile / FindClose. Please see:[^].
[EDIT: answering a follow-up question]
Pay attention that these functions find all file system objects in a current directory: both files and directories. Pay attention that the structure _WIN32_FIND_DATA has the field dwFileAttributes, the values of the fields are FILE_ATTRIBUTE_… constants, and one of the attributes is FILE_ATTRIBUTE_DIRECTORY. You can test if this bit is set in the field dwFileAttributes for each found item, and, if this is a directory, recursively find files in it.
Please see:[^],[^].
Is it clear now?
You could easily find this information by yourself.
VJ Reddy at 23-Apr-12 12:43pm
Good reference. 5!
SAKryukov at 23-Apr-12 12:47pm
Thank you, VJ.
SAKryukov at 23-Apr-12 12:51pm
[OP commented, moved from "Solution 2", which is not an answer:]
I know this functions, but I'd like to know How to go through the all subdirectories.
If there is a good code and It's not necessary to write code by myself.
SAKryukov at 23-Apr-12 12:51pm
[phil.o commented in reply:]
Better job done by others?
I'm not sure...
Come on, give it a try, and come back here when/if you are stuck.
Here is not a code-supermarket.
SAKryukov at 23-Apr-12 12:55pm
@JOHN 602:
First of all, please do us a favor: don't post non-answers as answers. Such posts will be removed, no one gets e-mail notification. Use "Have a Question or Comment", "Reply" to comment a question/answer or reply to existing comment, or use "Improve question".
As to your question: no, you don't know these functions, otherwise you would see that they walk you through the subdirectories. Please read those MSDN pages again, see the MSDN code samples. Everything is clearly explained.
Sergey Alexandrovich Kryukov at 1-Oct-12 11:39am
Well, I can see that you can read, thank you for your information. :-)

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

  Print Answers RSS
0 OriginalGriff 443
1 Sergey Alexandrovich Kryukov 197
2 PhilLenoir 145
3 RyanDev 125
4 Richard Deeming 120
0 Sergey Alexandrovich Kryukov 6,415
1 OriginalGriff 5,856
2 CPallini 2,473
3 Richard MacCutchan 1,667
4 Abhinav S 1,530

Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 4 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100