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. how to find a file in one folder

how to find a file in one folder

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
4 Posts 4 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.
  • Z Offline
    Z Offline
    zhangguoliming
    wrote on last edited by
    #1

    hi, as the titel.The user will input the name of the file and the folder through EDITBOX. m_name is the Variable ,in CStrig. Here is mz code void CFilefindDlg::OnButton1() { // TODO: Add your control notification handler code here HANDLE handle; WIN32_FIND_DATA fd; handle = FindFirstFile(m_name, &fd); if (handle != INVALID_HANDLE_VALUE) AfxMessageBox("Find this folder."); else AfxMessageBox("Could not find folder."); } I dont how to use funktion FindFirstFile().If i write in char path[256]="C:\\guo\\1.txt"; handle = FindFirstFile(path, &fd); It is right. But the name of the file should be decided by the user. How can i do it ?:doh::doh::doh: Thanks!

    B H T 3 Replies Last reply
    0
    • Z zhangguoliming

      hi, as the titel.The user will input the name of the file and the folder through EDITBOX. m_name is the Variable ,in CStrig. Here is mz code void CFilefindDlg::OnButton1() { // TODO: Add your control notification handler code here HANDLE handle; WIN32_FIND_DATA fd; handle = FindFirstFile(m_name, &fd); if (handle != INVALID_HANDLE_VALUE) AfxMessageBox("Find this folder."); else AfxMessageBox("Could not find folder."); } I dont how to use funktion FindFirstFile().If i write in char path[256]="C:\\guo\\1.txt"; handle = FindFirstFile(path, &fd); It is right. But the name of the file should be decided by the user. How can i do it ?:doh::doh::doh: Thanks!

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      If I'm understanding your situation correctly, your dialog box has an edit control and a button to initiate a "file search". You created a member variable for the edit control in the dialog class. This member variable is of type CString? If so, the string variable will not get updated until the data exchange routines run. Instead, you want access to the edit control directly so create a variable for the edit of type CEdit. If your using VC++ 6.0, in the ClassWizard, for the dialog class, under the member variables tab, select your edit control, click "Add Variable...", for "Category:" choose "control" and then select CEdit for the "Variable Type:". This way you can do the following with your code snippet... void CFilefindDlg::OnButton1() { // TODO: Add your control notification handler code here HANDLE handle=NULL; WIN32_FIND_DATA fd={0}; CString sFile=""; m_editName.GetWindowText(sFile); handle = FindFirstFile(sFile, &fd); if (handle != INVALID_HANDLE_VALUE) { AfxMessageBox("Find this folder."); } else { AfxMessageBox("Could not find folder."); } }

      1 Reply Last reply
      0
      • Z zhangguoliming

        hi, as the titel.The user will input the name of the file and the folder through EDITBOX. m_name is the Variable ,in CStrig. Here is mz code void CFilefindDlg::OnButton1() { // TODO: Add your control notification handler code here HANDLE handle; WIN32_FIND_DATA fd; handle = FindFirstFile(m_name, &fd); if (handle != INVALID_HANDLE_VALUE) AfxMessageBox("Find this folder."); else AfxMessageBox("Could not find folder."); } I dont how to use funktion FindFirstFile().If i write in char path[256]="C:\\guo\\1.txt"; handle = FindFirstFile(path, &fd); It is right. But the name of the file should be decided by the user. How can i do it ?:doh::doh::doh: Thanks!

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        I think you need to CString::Insert becuase you need a string(path) and need to a file name


        WhiteSky


        1 Reply Last reply
        0
        • Z zhangguoliming

          hi, as the titel.The user will input the name of the file and the folder through EDITBOX. m_name is the Variable ,in CStrig. Here is mz code void CFilefindDlg::OnButton1() { // TODO: Add your control notification handler code here HANDLE handle; WIN32_FIND_DATA fd; handle = FindFirstFile(m_name, &fd); if (handle != INVALID_HANDLE_VALUE) AfxMessageBox("Find this folder."); else AfxMessageBox("Could not find folder."); } I dont how to use funktion FindFirstFile().If i write in char path[256]="C:\\guo\\1.txt"; handle = FindFirstFile(path, &fd); It is right. But the name of the file should be decided by the user. How can i do it ?:doh::doh::doh: Thanks!

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          zhangguoliming wrote:

          handle = FindFirstFile(path, &fd);

          better use Direct Api PathFileExist

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

          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