|
-
March 24th, 2003, 06:04 PM
#1
Read file names
Very new to visual C++. I used Borland at school. I have visual C++ 5.0. What i want to do is read a folder and saving the names of the files of particular type to a txt file. I know how to do this in .NET classes but i don't know what classes i should use for what i have now. Thanks for your help.
-
March 24th, 2003, 10:22 PM
#2
Hi,
Start looking at
http://msdn.microsoft.com/library/de...attributes.asp
For a class who deals with file in MFC look at CFile, CStdioFile.
Regards,
Emanuel Vaduva
-
March 25th, 2003, 10:01 AM
#3
Thanks for the info. I found cfile earlier but the problem is i don't know how to do the include file so i can use it. Visual C++ is very frustratiting to me. I try to use certain classes but don't know what to include so i can use them. I know it's in MFC and i make a MFC app using the wizard but it won't let me use cfile. The included samples and help files are no help at all.
-
March 25th, 2003, 12:47 PM
#4
ok i got cfile to work. Now i need to be able to search a directory for a particular type of file *.mp3 something like that.
char* pFileName = "test.txt";
CFile file(pFileName, CFile::modeCreate | CFile::modeWrite);
CFile mp3file(HERE IS THE PROBLEM, CFile::modeRead);
// I want it to find every mp3 file in the directory and record it to a new file called test.txt. I don't think CFile can do this. Is there another way?
CString mp3name = mp3file.GetFileName();
int mp3length = mp3name.GetLength();
file.Write(mp3name, mp3length - 4);
file.Write(", ", 2);
-
March 25th, 2003, 12:55 PM
#5
Did you look at the link I send? There is a sample for how to use FindFirstFile, FindNextFile.
Regards,
Emanuel Vaduva
-
March 25th, 2003, 12:58 PM
#6
wow i finally did it. These help files are way to jumbled. Can't find what you want unless you know the exact name of the object. Who new there was a CFileFind?
-
March 25th, 2003, 03:06 PM
#7
Thanks for the help Emi. I have one more question. How would you use findnextfile to also look into other directories. Lets say search the whole hardrive for mp3 files.
-
March 25th, 2003, 03:30 PM
#8
Use recursive methods/functions.
Look at this sample
http://www.codeguru.com/forum/showth...hreadid=227926
Regards,
Emanuel Vaduva
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
|