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: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Browsing through files in folders, the compare

 
0
  #1
Jun 17th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,412
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Browsing through files in folders, the compare

 
0
  #2
Jun 18th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Re: Browsing through files in folders, the compare

 
0
  #3
Jun 18th, 2008
Thanks for the super fast reply. I'll give it a try 1st. Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Re: Browsing through files in folders, the compare

 
0
  #4
Jun 18th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,412
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Browsing through files in folders, the compare

 
0
  #5
Jun 18th, 2008
TCHAR is defined in tchar.h. LPTSTR and LPCTSTR as well as a lot of others are defined in windows.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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Re: Browsing through files in folders, the compare

 
0
  #6
Jun 18th, 2008
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);
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,412
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Browsing through files in folders, the compare

 
0
  #7
Jun 18th, 2008
>>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.
  1. char searchPath[MAX_PATH];
  2. strcpy(searchPath, "c:\\*.h");
  3. ...
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Re: Browsing through files in folders, the compare

 
0
  #8
Jun 18th, 2008
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'
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,861
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: Browsing through files in folders, the compare

 
0
  #9
Jun 18th, 2008
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:
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,412
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Browsing through files in folders, the compare

 
0
  #10
Jun 18th, 2008
>>strcpy(searchPath, L"c:\\*.h");
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC