Click to See Complete Forum and Search --> : Can Anyone help me?


ept5452
June 21st, 1999, 02:33 PM
I am trying to select multiple file names from a single directory, however, I am only allowed to select 14 files until I get an error. I need to be able to select in the 1000's of
files. Is this possible and if so, what do I need to change in the following code?



CString szFileList2(""),szTemp2,Nameb,Nameb1,Nameb2,FileListb2("");
CFileDialog m_ldFile2(TRUE, _T("*"), NULL,
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,
_T("Raw Files (*.raw)|*.raw|All Files (*.*)|*.*||"));
if (m_ldFile2.DoModal() == IDOK)
{
POSITION pos = m_ldFile2.GetStartPosition();
while (pos)
{
szTemp2 = m_ldFile2.GetNextPathName(pos) + " ";
m_B.Add(szTemp2);
jj=jj+1;
j=jj;
}

}

for( int x=0; x<i; x++)
{
Nameb=m_B[x];
Nameb.MakeReverse();
y=Nameb.Find('\\');
Nameb1=Nameb.Left(y);
Nameb1.MakeReverse();
Nameb2=Nameb1 + " ";
m_B2.Add(Nameb2);
FileListb2+=Nameb2;
}
m_sInput2=FileListb2;
UpdateData(FALSE);






Thank you,

Erik Toth

Paul McKenzie
June 21st, 1999, 03:54 PM
Yes, you should be able to select many more files than 14. The problem is not that you are not allowed to select the files. The problem is the code that you wrote that does something with the selected files is bad. I'm not sure what you're trying to do, but I would suggest using a debugger to solve the problem. Also, why not code a simple counting loop without the string manipulation to convince yourself that you have indeed selected 1000 files?


if (m_ldFile2.DoModal() == IDOK)
{
int nCount = 0;
POSITION pos = m_ldFile2.GetStartPosition();
while (pos)
{
nCount++;
m_ldFile2.GetNextPathName(pos);
}
CString strMsg;
strMsg.Format("I have selected %d files", nCount);
AfxMessageBox(strMsg);




Regards,

Paul McKenzie

Sam Hobbs
June 21st, 1999, 06:27 PM
The documentation for CFileDialog says (in part):

"To allow the user to select multiple files, set the OFN_ALLOWMULTISELECT flag before calling DoModal. You need to supply your own filename buffer to accommodate the returned list of multiple filenames. Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal. Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile."

Did you do that?