|
-
March 14th, 2005, 04:03 PM
#1
Enumerating Directory files in Win32 Console APP
I am just learning C++ I was wondering if someone can point me in the right direction to enumerate files in a directory in a win32 console app. I am using Visual Studio 02 .net as a IDE. This is what I have so far, and if someone can help, can you explain how you did it. Thanks greatly appreciated
#include <iostream>
using namespace System;
using namespace System::IO;
using namespace std;
//Function Prototypes
int menu();
int DoTaskHelp();
int AllFiles();
int main()
{
bool exit = false;
for(;
{
int choice = menu();
switch(choice)
{
case (1):
DoTaskHelp();
break;
case (2):
exit = true;
break;
case (3):
AllFiles();
}//end switch
if (exit)
break;
}//end forever
return 0;
}
int menu()
{
int choice;
cout << "\t**********\n \t MENU\n\t**********\n***Created by F. Shearer***\n\n";
cout <<"(1) Help. \n";
cout <<"(2) Exit. \n";
cout <<"(3) Search. \n";
cout << " ";
cin >> choice;
return choice;
}
int DoTaskHelp()
{
cout <<"No help info at this time!\n\n";
return 0;
}
int AllFiles()
{
int drive;
//Choose drive and dispaly directories
cout <<"Enter Drive you want to search: ";
cin >> drive;
//drive to search directories
DirectoryInfo* Info = new DirectoryInfo();
return 0;
}
-
March 14th, 2005, 04:57 PM
#2
Re: Enumerating Directory files in Win32 Console APP
DirectoryInfo is the .NET way. You can call GetFiles() mothod that will return a FileInfo array.
You can do it in C++ with Win32 API this way.
PS: do you mean recursivly or not?
Last edited by cilu; March 14th, 2005 at 04:59 PM.
-
March 15th, 2005, 12:01 AM
#3
Re: Enumerating Directory files in Win32 Console APP
WIN32_FIND_DATA FindFileData;
HANDLE hFile = FindFirstFile(strFolderName,&FindFileData);
//Now run in a loop of all the files and folders under this folder
while(hFile && FindNextFile(hFile,&FindFileData))
{
//Ignore system directories "." and ".." the good old MS-DOS days
if( (stricmp(FindFileData.cFileName,".")!=0) && (stricmp (FindFileData.cFileName,"..")!=0) && (stricmp(FindFileData.cFileName,"") !=0) && (FindFileData.nFileSizeLow > 0))
{
if(!((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) || (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) )
{
char szFile[256] = "";
sprintf(szFile, "%s%s", szPath, FindFileData.cFileName);
}
}
-
March 15th, 2005, 04:56 AM
#4
Re: Enumerating Directory files in Win32 Console APP
Please use CODE tags to wrap your code.
-
March 15th, 2005, 03:00 PM
#5
Re: Enumerating Directory files in Win32 Console APP
-
March 15th, 2005, 03:01 PM
#6
Re: Enumerating Directory files in Win32 Console APP
Thanks for the help guys!
-
March 15th, 2005, 03:45 PM
#7
Re: Enumerating Directory files in Win32 Console APP
 Originally Posted by fshearer
What r code tags?
Code tags are tags use to format the code. When you post, take a look at the button that says "Code". Use it to wrap the tags aroung your code.
Here is the effect of using code tags:
Code:
#include <iostream>
using namespace System;
using namespace System::IO;
-
March 15th, 2005, 04:32 PM
#8
Re: Enumerating Directory files in Win32 Console APP
Thanks for the info. I will do that from now on
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|