Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 10-Jul-13 19:32pm
v4
Comments
The_Inventor 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 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

I would set a breakpoint on the line
C++
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
C++
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
C++
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900