Click here to Skip to main content
11,638,351 members (78,715 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6
Hi All


i want to know that this code return me by doing directory scanning from directory that next file is present am using bool which give me presence of file with signal 1.
i want to write the names of files how

  CFileFind find;
	    CString path="C:\\TestFile";
	    if(path.Right(1) != "\\")
     	path += "\\";
     	path += "*.txt*";
  	    BOOL found = find.FindFile(path);
	    while (found)
		{
		found = find.FindNextFile();
         // here i need name of file also how to get the name of file 
		if(find.IsDots())
			continue;
		}
here

found is bool it scan the directory and run the loop untill files are available

i want to write the names of files also how to do that then i have to use the name of file further

plz help
Posted 9-May-12 19:51pm
prog786388
Comments
enhzflep at 10-May-12 2:17am
   
Well, since you are using a an instance of the CFileFind class - 'find', you can msdn CFileName for an explanation of it's member functions. One of these will surely return the name of the current file. - it does! GetFileName(), of all things.. It's a CString that is returned.

You may choose to use a vector of CStrings to hold the list of matching filenames.
i.e
vector matchingFiles;
found = find.FindNextFile();
// When you get a CString of the cur filename matching *.txt*, save it
matchingFiles.push_back(found.GetFileName());
Peter_in_2780 at 10-May-12 2:57am
   
That's an answer, not a comment. Promote it
Chuck O'Toole at 10-May-12 2:59am
   
How can you possibly be using some members of the CFileFind Class (FindFile(), FindNextFile()) without knowing / looking up the other class members? Is this code something you just cut / pasted from the web somewhere? Double-Click on CFileFind (to highlight it) and hit "F1". Read the displayed documentation.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, since you are using a an instance of the CFileFind class - 'find', you can msdn CFileName for an explanation of it's member functions. One of these will surely return the name of the current file. - it does! GetFileName(), of all things.. It's a CString that is returned.

You may choose to use a vector of CStrings to hold the list of matching filenames.
i.e
vector matchingFiles;
found = find.FindNextFile();
// When you get a CString of the cur filename matching *.txt*, save it
matchingFiles.push_back(found.GetFileName());

And yeah, what Chuck said.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 348
1 Sergey Alexandrovich Kryukov 314
2 stibee 288
3 OriginalGriff 190
4 Mika Wendelius 185
0 OriginalGriff 9,051
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,034
3 Suvendu Shekhar Giri 2,425
4 F-ES Sitecore 2,408


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 10 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100