Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using FindFirstFile

Using FindFirstFile

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Moochie5
    wrote on last edited by
    #1

    I am making a program that copies files with certain file extensions, such as .txt, to other directories that are created by the program. I am having difficulty using FindFirstFile. The problem I am having is selecting the directory and all the files with the .txt extensions. For example, this line of code finds all the txt files in the folder where this program is: hSearch = FindFirstFile(TEXT("*.txt"), &FileData); But, I say I need to get all of the .txt files on my c:\txtfiles directory. What is the correct code to do that? I have tried many things, the one that has worked best is this one. hSearch=FindFirstFile(TEXT("c:\\txtfiles\\*.txt"), &FileData); However with this one if there is more than one txt file in the directory my error will say could not find text files. If I leave just one txt file in the directory it will work. I am just looking for the correct code to copy all txt files from a directory on my c drive. Thanks.

    D F 2 Replies Last reply
    0
    • M Moochie5

      I am making a program that copies files with certain file extensions, such as .txt, to other directories that are created by the program. I am having difficulty using FindFirstFile. The problem I am having is selecting the directory and all the files with the .txt extensions. For example, this line of code finds all the txt files in the folder where this program is: hSearch = FindFirstFile(TEXT("*.txt"), &FileData); But, I say I need to get all of the .txt files on my c:\txtfiles directory. What is the correct code to do that? I have tried many things, the one that has worked best is this one. hSearch=FindFirstFile(TEXT("c:\\txtfiles\\*.txt"), &FileData); However with this one if there is more than one txt file in the directory my error will say could not find text files. If I leave just one txt file in the directory it will work. I am just looking for the correct code to copy all txt files from a directory on my c drive. Thanks.

      D Offline
      D Offline
      Dreamz
      wrote on last edited by
      #2

      Check this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/listing_the_files_in_a_directory.asp[^] Hope this will help you ...

      1 Reply Last reply
      0
      • M Moochie5

        I am making a program that copies files with certain file extensions, such as .txt, to other directories that are created by the program. I am having difficulty using FindFirstFile. The problem I am having is selecting the directory and all the files with the .txt extensions. For example, this line of code finds all the txt files in the folder where this program is: hSearch = FindFirstFile(TEXT("*.txt"), &FileData); But, I say I need to get all of the .txt files on my c:\txtfiles directory. What is the correct code to do that? I have tried many things, the one that has worked best is this one. hSearch=FindFirstFile(TEXT("c:\\txtfiles\\*.txt"), &FileData); However with this one if there is more than one txt file in the directory my error will say could not find text files. If I leave just one txt file in the directory it will work. I am just looking for the correct code to copy all txt files from a directory on my c drive. Thanks.

        F Offline
        F Offline
        fogmen
        wrote on last edited by
        #3

        u can try about this: CString szFilePath ,szFileType ,szFileMask ; szFilePath = "c:\\"; szFileType = "*.txt"; szFileMask = szFilePath + szFileType; hFile = FindFirstFile(szFileMask,&FindFileData); while(hFile != INVALID_HANDLE_VALUE) { //do copy operation if(!FindNextFile(hFile,&FindFileData)) break; }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups