Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

1 solution

This can be done with Windows API FindFirstFile (FindFirstFileEx) / FindNextFile / FindClose. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418%28v=vs.85%29.aspx[^].

[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:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365740%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx[^].

Is it clear now?

You could easily find this information by yourself.

—SA
 
Share this answer
 
v4
Comments
VJ Reddy 23-Apr-12 12:43pm    
Good reference. 5!
Sergey Alexandrovich Kryukov 23-Apr-12 12:47pm    
Thank you, VJ.
--SA
Sergey Alexandrovich Kryukov 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.
Sergey Alexandrovich Kryukov 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.
Sergey Alexandrovich Kryukov 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.

--SA

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