| | |
Browsing through files in folders, the compare
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 89
Reputation:
Solved Threads: 7
Hi,
I've been given the following task:
1. Read some .h header files from a few different folder in different directories.
2. Extract only the functions in the files and store all of them into a single text file.
3. Repeat the step 1 and 2 again but extract info from different files and store them in
another different text file.
4. Compare the functions in the text files. (Both the function name and their parameters)
I'm using the function fopen() to open the file and have to specify the path for each of the file one by one (there are more than 200 files!). Is there any way for me to automatically browse through all the files in a specific folder then proceed to another? Some suggest me to include the "dirent.h" header but it show ""fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory".
The Step 2 i'm using string to read the char in the files and store them in string which are later on copy into a List.
I've been given the following task:
1. Read some .h header files from a few different folder in different directories.
2. Extract only the functions in the files and store all of them into a single text file.
3. Repeat the step 1 and 2 again but extract info from different files and store them in
another different text file.
4. Compare the functions in the text files. (Both the function name and their parameters)
I'm using the function fopen() to open the file and have to specify the path for each of the file one by one (there are more than 200 files!). Is there any way for me to automatically browse through all the files in a specific folder then proceed to another? Some suggest me to include the "dirent.h" header but it show ""fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory".
The Step 2 i'm using string to read the char in the files and store them in string which are later on copy into a List.
Are you using *nix or MS-Windows ? If MS-Windows you can use FindFirstFile() and FindNextFile() to get the file names. See examples on MSDN and here at DaniWeb.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jun 2008
Posts: 89
Reputation:
Solved Threads: 7
Hi,
I'm still struggling to scan all the directories of the files. Tried to use the FindFirstFile() and FindNextFile() and the FindData() and PathAppend(). But having problem to understand the variuos type of data type i havent seen before such as TCHAR LPTSTR LPCTSTR and etc. Any refference that might help? Or can you please show me some example?
Thanks.
I'm still struggling to scan all the directories of the files. Tried to use the FindFirstFile() and FindNextFile() and the FindData() and PathAppend(). But having problem to understand the variuos type of data type i havent seen before such as TCHAR LPTSTR LPCTSTR and etc. Any refference that might help? Or can you please show me some example?
Thanks.
•
•
Join Date: Jun 2008
Posts: 89
Reputation:
Solved Threads: 7
Hi,
1. This is the code i get some where online. Why i get an error message stating that " error C3861: '_T': identifier not found"?
2. and where actually i should place the wildcard for me to search files of certain type (for exp: .h)?
3. Sorry if i ask any stupid question cause i'm still new in C++ programming.
#include <iosteream>
#include <Shlwapi.h> // for PathAppend()
using namespace std;
void EnumerateFolderFS(LPCTSTR path)
{
TCHAR searchPath[MAX_PATH];
// a wildcard needs to be added to the end of the path, e.g. "C:\*"
lstrcpy(searchPath, path);
PathAppend(searchPath, _T("*")); // defined in shell lightweight API (v4.71)
WIN32_FIND_DATA ffd; // file information struct
HANDLE sh = FindFirstFile(searchPath, &ffd);
if(INVALID_HANDLE_VALUE == sh) return; // not a proper path i guess
// enumerate all items; NOTE: FindFirstFile has already got info for an item
do {
cout << "Name = " << ffd.cFileName << endl;
cout << "Type = " << ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
? "dir\n" : "file\n" );
cout << "Size = " << ffd.nFileSizeLow << endl;
} while (FindNextFile(sh, &ffd));
FindClose(sh);
}
1. This is the code i get some where online. Why i get an error message stating that " error C3861: '_T': identifier not found"?
2. and where actually i should place the wildcard for me to search files of certain type (for exp: .h)?
3. Sorry if i ask any stupid question cause i'm still new in C++ programming.
#include <iosteream>
#include <Shlwapi.h> // for PathAppend()
using namespace std;
void EnumerateFolderFS(LPCTSTR path)
{
TCHAR searchPath[MAX_PATH];
// a wildcard needs to be added to the end of the path, e.g. "C:\*"
lstrcpy(searchPath, path);
PathAppend(searchPath, _T("*")); // defined in shell lightweight API (v4.71)
WIN32_FIND_DATA ffd; // file information struct
HANDLE sh = FindFirstFile(searchPath, &ffd);
if(INVALID_HANDLE_VALUE == sh) return; // not a proper path i guess
// enumerate all items; NOTE: FindFirstFile has already got info for an item
do {
cout << "Name = " << ffd.cFileName << endl;
cout << "Type = " << ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
? "dir\n" : "file\n" );
cout << "Size = " << ffd.nFileSizeLow << endl;
} while (FindNextFile(sh, &ffd));
FindClose(sh);
}
>>This is the code i get some where online. Why i get an error message stating that " error C3861: '_T': identifier not found"?
You have to include tchar.h
>>2. and where actually i should place the wildcard for me to search files of certain type (for exp: .h)?
In the FindFirst() function call. Unless you want UNICODE support I'd replace TCHAR and _T macros to make the code more readable.
You have to include tchar.h
>>2. and where actually i should place the wildcard for me to search files of certain type (for exp: .h)?
In the FindFirst() function call. Unless you want UNICODE support I'd replace TCHAR and _T macros to make the code more readable.
C++ Syntax (Toggle Plain Text)
char searchPath[MAX_PATH]; strcpy(searchPath, "c:\\*.h"); ...
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jun 2008
Posts: 89
Reputation:
Solved Threads: 7
Hi, Ancient Dragon
Did you try to compile? It will still have syntax errors:
1. 'strcpy' : cannot convert parameter 2 from 'LPCTSTR' to 'const char *'
2. 'PathAppendW' : cannot convert parameter 1 from 'char [260]' to 'LPWSTR'
3. 'FindFirstFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Did you try to compile? It will still have syntax errors:
1. 'strcpy' : cannot convert parameter 2 from 'LPCTSTR' to 'const char *'
2. 'PathAppendW' : cannot convert parameter 1 from 'char [260]' to 'LPWSTR'
3. 'FindFirstFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Do you need to use UNICODE? If not, turn it of, and all your problems will be gone. (as AD mentioned)
If you do need it:
Change this:
to this:
Do the same with all the 'const char *' (== text between " ") and you're done.
If you do need it:
Change this:
strcpy(searchPath, "c:\\*.h"); to this:
strcpy(searchPath, L"c:\\*.h"); Do the same with all the 'const char *' (== text between " ") and you're done.
Last edited by niek_e; Jun 18th, 2008 at 6:18 am.
>>strcpy(searchPath, L"c:\\*.h");
That doesn't work because strcpy() requires char*, not wchar_t* Instead use _tcscpy()
Note that _tcscpy() is a macro defined in tchar.h which translates to either strcpy() when UNICODE is undefined or wcscpy() for UNICODE.
That doesn't work because strcpy() requires char*, not wchar_t* Instead use _tcscpy()
_tcscpy(searchPath, _T("c:\\*.h")); Note that _tcscpy() is a macro defined in tchar.h which translates to either strcpy() when UNICODE is undefined or wcscpy() for UNICODE.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Slow browsing and slow PC (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: How to setup Borland C++ IDE Environment
- Next Thread: Hangman help
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






