FindFirstFile()

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 58
Reputation: Darth Vader is an unknown quantity at this point 
Solved Threads: 0
Darth Vader Darth Vader is offline Offline
Junior Poster in Training

FindFirstFile()

 
0
  #1
Feb 9th, 2008
Hello everyone. I have attached a folderBrowserDialog1 to my Form1.
To a button I will do a function.
What I will do now is when I press the button, I want to open this folderBrowserDialog wich works fine.
After this I will click on a folder wich contains *.txt Files and press OK.
What will happen now is that all these .txt files names will appear in my textBox1.
I am trying this code out but really dont know what could be wrong.
I am trying to first FindFirstFile() but my compiler doesn´t compile.
What could be missing ?

  1. folderBrowserDialog1->ShowDialog();
  2.  
  3. HANDLE h;
  4. WIN32_FIND_DATA lpFileName;
  5. h = ::FindFirstFile(folderBrowserDialog1->SelectedPath, &lpFileName);
  6.  
  7. this->textBox1->Text = h;
Thanks
Last edited by Darth Vader; Feb 9th, 2008 at 6:48 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,597
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1489
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: FindFirstFile()

 
0
  #2
Feb 9th, 2008
1. The second parameter is not a filename, but a structure that contains a lot of fields including the filename. Look up FindFirstFile() in MSDN and you will see that that structure contains.

2. FindFirstFile returns a HANDLE. Setting this->textBox1->Text = h is just flat wrong. you should be setting it to the char array filename thats in the structure.

If you search the code snippets you will find a couple very extensive programs that use FindFirstFile() and FindNextFile().
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: Darth Vader is an unknown quantity at this point 
Solved Threads: 0
Darth Vader Darth Vader is offline Offline
Junior Poster in Training

Re: FindFirstFile()

 
0
  #3
Feb 9th, 2008
If I begin with this code as I have closed out one line (//).
What will I need to make this compile. I beleive I am missing some basic things for this function to work:
Notice that I am Browsing a folder. Somthing is wrong with "&lpFileName" but from here I dont know how to continue.

  1. folderBrowserDialog1->ShowDialog();
  2.  
  3. HANDLE h;
  4. WIN32_FIND_DATA lpFileName;
  5. h = ::FindFirstFile(folderBrowserDialog1->SelectedPath, &lpFileName);
  6.  
  7. // this->textBox1->Text = h;

Thank You...


I have looked around for examples but cant really get it right what is needed to do.
I found this code but are not sure if I should need something of this in my actual code.

So "&lpFileName" in my actual code is the same as "ffd" in this code. But nothing is done to "ffd" and will refer to it as I have done. So I am a bit lost here where to start.

I need to understand what this structure is that represents "&IpFileName" in my code.( This Line )
  1. h = ::FindFirstFile(folderBrowserDialog1->SelectedPath, &lpFileName);

  1.  
  2. WIN32_FIND_DATA ffd;
  3. TCHAR szDir[MAX_PATH];
  4. size_t length_of_arg;
  5. HANDLE hFind = INVALID_HANDLE_VALUE;
  6. DWORD dwError=0;
Link for whole code:
http://msdn2.microsoft.com/en-us/lib...00(VS.85).aspx




Originally Posted by Ancient Dragon View Post
1. The second parameter is not a filename, but a structure that contains a lot of fields including the filename. Look up FindFirstFile() in MSDN and you will see that that structure contains.

2. FindFirstFile returns a HANDLE. Setting this->textBox1->Text = h is just flat wrong. you should be setting it to the char array filename thats in the structure.

If you search the code snippets you will find a couple very extensive programs that use FindFirstFile() and FindNextFile().
Last edited by Darth Vader; Feb 9th, 2008 at 8:12 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC