Categories

CODE
Visual C++ Programming
C++ (Non Visual C++ Issues)
Modern Windows Apps (Metro)
C++ and WinAPI
Managed C++ and C++/CLI
Visual C++ Bugs & Fixes
Graphics Programming
Multithreading
Network Programming
Driver Development
Visual Basic 6.0 Programming
Visual Basic .NET
Crystal Reports
C-Sharp Programming
Managed C++
Visual Basic .NET
ASP.NET
.NET Framework
ADO.NET
Windows Presentation Foundation (WPF) & XAML forum
Silverlight
.NET Installation and Configuration Issues
Java Programming
AJAX
Scripting - Client Side
Database
XML
Wireless/Mobile Development
Assembly
Scripting - Server Side (PHP, Perl, etc.)
Python
General Developer Topics
Project Planning, Design, and Management
Testers and Testing
Algorithms & Data Structures
General Discussion / Chit Chat
Announcements, Press Releases, & News
Feedback
Articles Suggestions
Testing Area
Programming Projects
C# Game(s) Project
Game Engine Project
C++ Coding Project
Project: Code War
Slow Chat: Talk with Microsoft Developer Teams
Slow Chat: Developing Multithreaded Applications
Slow Chat: C++0x
Slow Chat: Visual C++: Yesterday, Today, and Tomorrow
Directory Services
General Windows and DNA Programming
Windows OS Issues
Open Positions (Jobs)
Looking for Work
Visual Basic .NET FAQs
Visual Basic FAQs
CodeGuru Individual FAQs
CodeGuru Individual Visual Basic FAQs

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Visual C++ Programming

Ask questions about Windows programming with Visual C++ and help others by answering their questions.

Findfirst() and findNext() in C


I would like to know the usage of findfirst and findnext functions in C ..I am compiling using VC++ 2008 compiler.    Here i googled about these functions example. but the examples concept is listing the files in a current directory..    IS it possible to read the directory path given in console window and find the *.txt extension in that folder and do the process and findnext file in the same directory?    If u know any quiet situable example.kindly provide me the links..    I tired the below example.Always getting conversion errors.How can i change these conversion.especially reading the strcpy(),strcat();.I dont think these functions are correct usuage in VC++ 2008 editor.      	Code:  	#include "stdafx.h"  #include <string>  #include <vector>  #include <windows.h>  #include <atlstr.h>  #include <tchar.h>  #include <stdio.h>   #define MAX_PATH_LENGTH 256    int main(int argc, char *argv[])  {  int i;  int pathlength=100;    //char *path;  //path=(char *)malloc((MAX_PATH_LENGTH) * sizeof(char));     char path[300];     //printf("Enter the path:");   //scanf_s("&#37;s",&path);    //printf("%s",path);    bool FindFilesFromFolder();   free(path);   getchar();   return 0;   }     bool FindFilesFromFolder()    {     HANDLE            hFile;     WIN32_FIND_DATA   FindFileData;     std::vector<char> fileList;       TCHAR chFolderpath[_MAX_PATH];     CString strExtension   = _T("*.B11");       strcpy(chFolderpath, _T("F:\\test\\"));     strcat(chFolderpath, strExtension);       hFile = FindFirstFile(chFolderpath, &FindFileData);       if (hFile == INVALID_HANDLE_VALUE) {  	   //printf("Invalid file handle.");  	   MessageBox(          NULL,          (LPCWSTR)L"Resource not available\nDo you want to try again?",          (LPCWSTR)L"Account Details",          MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2);                  return false;     }       CString filepath;       do     {          filepath.Format(_T("%s%s"), _T("F:\\test\\"), FindFileData.cFileName);        fileList.push_back(filepath);       } while(FindNextFile(hFile, &FindFileData));             return true;    }     				  			

  				  					Sure, it's possible but since you build for unicode you shouldn't use str*** functions. Use the unicode variants instead or if you prefer that make your code buildable both for multibyte & unicode and use the _t*** variant.    See here for all variants of the functions http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx    Edit: A general rule by the way is to stay away from casts as long as possible. Casts are dangerous so to use them you really need to know exactly what you're doing. They are not some kind of magic solution for whenever the compiler complains.  				  			

  				  					  	  		  			  			  				  					 Originally Posted by keerth516  					  				  				I would like to know the usage of findfirst and findnext functions in C ..I am compiling using VC++ 2008 compiler.  			  		  	   Since you are using MFC you could also use MFC CFileFind class rather than plain Win32 APIs.  And there is a FAQ...    Besides, mixing std::string, CString, _T() macro and UNICODE strings is very rarely could be a good idea, and your case does not belong to those " very rarely" ones.


Related Links

how do i associate a new file type in Registry
Chart Control
Getting the current user's ID in NT/Win2k
BSCMAKE: warning BK4503
RTC -&gt; Gregorian Conversion
Automate excel 97 sheet with vc++ 6
CStatic: How do I resize the Static based on the text in it ?
Why my Radio Button does not have display text next to it?
graphing
Proxy
Detect calling program name in DLL
USB programming
Urgent Help Needed! Please!
How to detect the maximize button is pressed?
What happened to my object?
Run other applications