Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing Files in c++

Status
Not open for further replies.

MsPeppa

Programmer
Jun 27, 2001
19
US
Hi,

I'm trying to write a piece of a larger program that will allow the user to view all the available .txt files in c:\projects\qrt4. I have no idea how to do this and have been searching the net for some info with no luck. So if anyone has any idea it would be greatly appreciated.. Thanx


MsPeppa
 
Using CFileFind you can give it a directory to look at. Through the use of "IsDirectory" function you can skip or travers sub directories and you can filter it for *.txt.

Matt
 
I Have a program that allows user to select a certain type of file.
I think I used GetOpenFilename (?)

I don't fully remember, but if you want I can send you the code for a dialog box in wich you can brows your directory
and filter for certain files.
P.s. Its a standard class in Visual C++

cheers,
Martini
 
Another one example (Compilled using VC++ 6.0 / MDI App):

void DoSomething (CString FN) {

/*Here You can do anything You want with file (FN - filename). This function will be called when next appropriate file will be found. Here You can, for example, add FN to array of CString's and then after the exit of ListFiles() display this array in dialog box or something else You need...*/

MessageBox (NULL, FN, "", MB_OK); /*Displays every file in message box*/
}

bool ListFiles () { //true if no such files found

_finddata_t fd;
long hFile;
CString FN;

if((hFile=_findfirst( "c:\\projects\\qrt4\\*.txt", &fd ))==-1L) {
return true;
} else {
FN=fd.name;
DoSomething (FN);
while( _findnext( hFile, &fd ) == 0 ) {
FN=fd.name;
DoSomething (FN);
}
_findclose( hFile );
}
}

... Tabaar ...
 
Also you can make your oown control based on FindFirstFile/FindNextFile. John Fill
1c.bmp


ivfmd@mail.md
 
Does anyone have an example of this, that is fully operational. I am having difficulties, figuring out what libraries I may need to run this?
 
If you are a COM user, you can use Excell.Application object for using such posibilities:


#include<atlbase.h>
#include<comdef.h>
int main()
{
CoInitialize(NULL);
{
CComPtr<IDispatch> pdExAp;
CComPtr<IUnknown> puExAp;
HRESULT hr;
hr=puExAp.CoCreateInstance(L&quot;Excel.Application&quot;,0,CLSCTX_LOCAL_SERVER);
if(FAILED(hr))
{
MessageBox(0,&quot;can't create instance&quot;,&quot;error&quot;,0);
}_variant_t x;
puExAp->QueryInterface(IID_IDispatch,(void**)&pdExAp);
_com_dispatch_method(pdExAp,0x00000433,DISPATCH_METHOD,0,0,0);//GetOpenFileName
_com_dispatch_method(pdExAp,0x00000434,DISPATCH_METHOD,0,0,0);//GetSaveFileName
}
CoUninitialize();
return 0;
}
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top