Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Can someone help me with this code below..It takes a path from a edit box(eg..c:\users and list files. The problem is when I press a button to go back a directory...it will not list all the files..just one directory or one file
 
void CAlDlg::OnButton1()
{
    m_b.ResetContent();
 
    UpdateData(true);
    CString left = m_o;
    UpdateData(false);
    CFileFind OneFile;
    CString FileName, DirName;
    BOOL BeWorking;
 
    int i = left.GetLength();
 
    for(int j = 0; j<i; j++)>
    {
        if (left[j] == '\\')
        {
            j++;
        }
    }
 
    CString howlong = left;
    UpdateData(true);
 
    CString gone = m_o;
    UpdateData(false);
    CString ocean = howlong + "*.*";
 
    BeWorking = OneFile.FindFile (ocean);
 
    while (BeWorking)
    {
        BeWorking = OneFile.FindNextFile () ;
 
        if(OneFile.IsDots()) continue;
 
        m_b.AddString(OneFile.GetFileName ());
 
        GetDlgItem(IDC_EDIT3)->SetWindowText(OneFile.GetRoot());
    }
    OneFile.Close ();
}
Posted 10-Jul-13 20:14pm
Edited 10-Jul-13 20:32pm
enhzflep38.2K
v4
Comments
The_Inventor at 11-Jul-13 2:02am
   
I will need to see the code for the 'm_b and m_o' variables and their datatype(s) and or class structure. Variable names in C++ start in lower case and have Capitals in the middle, fileName, dirName, oneFile, beWorking may work better. It isn't easy, but the compiler likes it. Also will need your CFileFind class, and then last, you may have too many UpdateData()'s, or conversely, not enough of them in the correct location in the lower part of the code block.
Richard MacCutchan at 11-Jul-13 9:03am
   
While it may be a common convention in C++, there is no rule that imposes this standard on variable names.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I would set a breakpoint on the line
BeWorking = OneFile.FindFile (ocean);
And look at the value of your filter expression (ocean). I would assume the problem is there.
 
As a general remark: This code is a dump. Haven't you taken a look at it at all? For example, the loop
    for(int j = 0; j<i;>
    {
        if (left[j] == '\\')
        {
            j++;
        }
    }
does not do anything at all. That might in fact be part of the problem, because in line
   CString ocean = howlong + "*.*";
you simply append "*.*". What if howlong contained "c:\users\abc"? The filter would be "c:\users\abc*.*" and that might indeed only return a result of one file or even less.
 
The variable gone is set but never used. I would first clean this code up and then step through it with a debugger.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 330
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100