CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Read file names

  1. #1
    Join Date
    Mar 2003
    Posts
    5

    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.

  2. #2
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573
    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

  3. #3
    Join Date
    Mar 2003
    Posts
    5
    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.

  4. #4
    Join Date
    Mar 2003
    Posts
    5
    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);

  5. #5
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573
    Did you look at the link I send? There is a sample for how to use FindFirstFile, FindNextFile.
    Regards,

    Emanuel Vaduva

  6. #6
    Join Date
    Mar 2003
    Posts
    5
    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?

  7. #7
    Join Date
    Mar 2003
    Posts
    5
    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.

  8. #8
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573
    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
  •  





Click Here to Expand Forum to Full Width

Featured