Click here to Skip to main content
Rate this: bad
good
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
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v4
Comments
VJ Reddy at 23-Apr-12 12:43pm
   
Good reference. 5!
SAKryukov at 23-Apr-12 12:47pm
   
Thank you, VJ.
--SA
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.
 
--SA
Sergey Alexandrovich Kryukov at 1-Oct-12 11:39am
   
Well, I can see that you can read, thank you for your information. :-)
--SA

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 420
1 _Amy 235
2 Andreas Gieriet 180
3 Peter Leow 175
4 Dave Kreskowiak 155
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,597
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | 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