Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
I need to find all files with a same extension on a drive... Posted by DiP on 14 May 2000 at 2:50 AM
Anyone could provide me an algorithm to do that?<br>
Something that covers all the folders starting from the root?<br>
Thanx.


Edit Report
Re: I need to find all files with a same extension on a drive... Posted by KMS on 14 May 2000 at 8:26 PM
Here's a complete prog. Will find jpg files in the drive you want, I've used the Win32 API FindFirstFile/FindNextFile, you can convert to C's findfirst/findnext easy if you want to..<br>
<br>
#include "windows.h"<br>
#include "stdio.h"<br>
<br>
void search_folder( const char *pszFolderName, const char *pszExt )<br>
{<br>
// add \*.* to folder name to search for all files and folders<br>
char szBuffer[ _MAX_PATH ];<br>
wsprintf( szBuffer, "%s\\*.*", pszFolderName );<br>
<br>
// find first file<br>
WIN32_FIND_DATA wfd;<br>
HANDLE h = FindFirstFile( szBuffer, &wfd );<br>
if( h != INVALID_HANDLE_VALUE )<br>
{<br>
do<br>
{<br>
// check if its a folder<br>
if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )<br>
{<br>
// skip . and .. or else we'd recurse to hell<br>
if( lstrcmpi( wfd.cFileName, "." ) && lstrcmpi( wfd.cFileName, ".." ) )<br>
{<br>
// build new folder name and search it<br>
wsprintf( szBuffer, "%s\\%s", pszFolderName, wfd.cFileName );<br>
search_folder( szBuffer, pszExt );<br>
}<br>
}<br>
else<br>
{<br>
// its a file, check extension<br>
char szTempExt[ _MAX_PATH ];<br>
_splitpath( wfd.cFileName, NULL, NULL, NULL, szTempExt );<br>
if( lstrcmpi( (char*) ( szTempExt + 1 ), pszExt ) == 0 )<br>
{<br>
// got one, build full file name and show it<br>
wsprintf( szBuffer, "%s\\%s", pszFolderName, wfd.cFileName );<br>
printf( "%s\n", szBuffer );<br>
}<br>
}<br>
}<br>
while( FindNextFile( h, &wfd ) ); // find next file<br>
<br>
CloseHandle( h );<br>
}<br>
}<br>
<br>
<br>
main()<br>
{<br>
search_folder( "c:", "jpg" );<br>
<br>
return 0;<br>
}<br>
<br>
<br>
: Anyone could provide me an algorithm to do that?<br>
: Something that covers all the folders starting from the root?<br>
: Thanx.<br>
: <br>
<br>






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.