-
August 4th, 2014, 10:54 AM
#1
Problem with CFileFind
A fairly simple loop:
Code:
if (rFinder.FindFile(strFolder + "\\*.*"))
{
while (rFinder.FindNextFile())
{
strPath = rFinder.GetFilePath();
.
.
.
.
}
}
What on earth would be causing this to only find directories - no files what so ever?
I also noticed that, in another test directory I was using, CFileFind failed to find this sub-directory directory: "HTML Codes - Table of ascii characters and symbols_files". It did find the single HTML file that was also in this directory however.
This class seems to be some what unreliable.
Perhaps I would be better off using the old fashioned C version: findfirst and findnext.
Last edited by gregaryb; August 4th, 2014 at 10:58 AM.
-
August 4th, 2014, 02:22 PM
#2
Re: Problem with CFileFind
What is rFinder?
What is strFolder?
What is strPath?
Please, post the complete code for searching the files.
Victor Nijegorodov
-
August 4th, 2014, 02:27 PM
#3
Re: Problem with CFileFind
Victor Nijegorodov
-
August 4th, 2014, 06:20 PM
#4
Re: Problem with CFileFind
void COtherFilesDialog::UploadFolder(CFileFind& rFinder, LPCSTR lpszFolder, LPCSTR lpszServerFolder)
{
CString strFolder = lpszFolder, strPath,
strServerFolder = lpszServerFolder,
strFolderSeperator = m_rIniFile.getKeyValue("FolderSeperator", "WebServer"),
strCWD1, strCWD2;
bool bIsTextFile = false;
if (rFinder.FindFile(strFolder + "\\*.*"))
{
while (rFinder.FindNextFile())
{
strPath = rFinder.GetFilePath();
if (rFinder.IsDots())
{
// Do nothing
}
else if (rFinder.IsDirectory())
{
CFileFind finder;
CString strFolderName = rFinder.GetFileName();
if (!((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strFolderName))
{
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->CreateServerFolder(strFolderName));
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strFolderName));
}
UploadFolder(finder, strPath, strServerFolder + strFolderSeperator + strFolderName);
((CEasyWebStoreUploaderDlg*)GetParent())->GetServerFolder(strCWD1);
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(".."));
((CEasyWebStoreUploaderDlg*)GetParent())->GetServerFolder(strCWD2);
}
else
{
bIsTextFile = IsTextFile(rFinder.GetFilePath());
((CEasyWebStoreUploaderDlg*)GetParent())->UploadFile(strPath, rFinder.GetFileName(), "", bIsTextFile);
}
}
}
}
void COtherFilesDialog::OnBnClickedButtonUploadWeb()
{
CFileFind finder;
CString strPublicHTML;
// if (ValidateWebFolder(GetWebFolder()))
{
strPublicHTML = m_rIniFile.getKeyValue("PublicHTML", "WebServer");
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strPublicHTML));
UploadFolder(finder, GetWebFolder(), strPublicHTML);
}
((CEasyWebStoreUploaderDlg*)GetParent())->SetLastCtrlID(IDC_BUTTON_UPLOAD_WEB);
}
-
August 4th, 2014, 06:21 PM
#5
Re: Problem with CFileFind
Originally Posted by gregaryb
A fairly simple loop:
Code:
if (rFinder.FindFile(strFolder + "\\*.*"))
{
while (rFinder.FindNextFile())
{
strPath = rFinder.GetFilePath();
.
.
.
.
}
}
What on earth would be causing this to only find directories - no files what so ever?
I also noticed that, in another test directory I was using, CFileFind failed to find this sub-directory directory: "HTML Codes - Table of ascii characters and symbols_files". It did find the single HTML file that was also in this directory however.
This class seems to be some what unreliable.
Perhaps I would be better off using the old fashioned C version: findfirst and findnext.
Code:
void COtherFilesDialog::UploadFolder(CFileFind& rFinder, LPCSTR lpszFolder, LPCSTR lpszServerFolder)
{
CString strFolder = lpszFolder, strPath,
strServerFolder = lpszServerFolder,
strFolderSeperator = m_rIniFile.getKeyValue("FolderSeperator", "WebServer"),
strCWD1, strCWD2;
bool bIsTextFile = false;
if (rFinder.FindFile(strFolder + "\\*.*"))
{
while (rFinder.FindNextFile())
{
strPath = rFinder.GetFilePath();
if (rFinder.IsDots())
{
// Do nothing
}
else if (rFinder.IsDirectory())
{
CFileFind finder;
CString strFolderName = rFinder.GetFileName();
if (!((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strFolderName))
{
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->CreateServerFolder(strFolderName));
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strFolderName));
}
UploadFolder(finder, strPath, strServerFolder + strFolderSeperator + strFolderName);
((CEasyWebStoreUploaderDlg*)GetParent())->GetServerFolder(strCWD1);
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(".."));
((CEasyWebStoreUploaderDlg*)GetParent())->GetServerFolder(strCWD2);
}
else
{
bIsTextFile = IsTextFile(rFinder.GetFilePath());
((CEasyWebStoreUploaderDlg*)GetParent())->UploadFile(strPath, rFinder.GetFileName(), "", bIsTextFile);
}
}
}
}
void COtherFilesDialog::OnBnClickedButtonUploadWeb()
{
CFileFind finder;
CString strPublicHTML;
// if (ValidateWebFolder(GetWebFolder()))
{
strPublicHTML = m_rIniFile.getKeyValue("PublicHTML", "WebServer");
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strPublicHTML));
UploadFolder(finder, GetWebFolder(), strPublicHTML);
}
((CEasyWebStoreUploaderDlg*)GetParent())->SetLastCtrlID(IDC_BUTTON_UPLOAD_WEB);
}
-
August 4th, 2014, 06:58 PM
#6
Re: Problem with CFileFind
I believe he was asking what values those variables contain.
-
August 4th, 2014, 07:17 PM
#7
Re: Problem with CFileFind
I change the function to make it similar to the CFileFind example:
Code:
void COtherFilesDialog::UploadFolder(LPCSTR lpszFolder, LPCSTR lpszServerFolder)
{
CString strFolder = lpszFolder, strPath,
strServerFolder = lpszServerFolder,
strFolderSeperator = m_rIniFile.getKeyValue("FolderSeperator", "WebServer"),
strCWD1, strCWD2;
bool bIsTextFile = false;
CFileFind finder;
strFolder += "\\*.*";
if (finder.FindFile(strFolder))
{
while (finder.FindNextFile())
{
strPath = finder.GetFilePath();
if (finder.IsDots())
continue;
else if (finder.IsDirectory())
{/*
CString strFolderName = finder.GetFileName();
if (!((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strFolderName))
{
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->CreateServerFolder(strFolderName));
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(strFolderName));
}
UploadFolder(strPath, strServerFolder + strFolderSeperator + strFolderName);
((CEasyWebStoreUploaderDlg*)GetParent())->GetServerFolder(strCWD1);
ASSERT(((CEasyWebStoreUploaderDlg*)GetParent())->SetServerFolder(".."));
((CEasyWebStoreUploaderDlg*)GetParent())->GetServerFolder(strCWD2);
*/
}
else
{
bIsTextFile = IsTextFile(finder.GetFilePath());
((CEasyWebStoreUploaderDlg*)GetParent())->UploadFile(strPath, finder.GetFileName(), "", bIsTextFile);
}
}
finder.Close();
}
}
I am using it on the following directory structure:
g:
test
links.txt
test
links.txt
But it does not work properly. My function only finds the following '.', '..', 'test' and 'test'.
It wont find any of the 'links.txt'
if I set a break point in the else statement it is never hit:
Code:
else
{
bIsTextFile = IsTextFile(finder.GetFilePath());
((CEasyWebStoreUploaderDlg*)GetParent())->UploadFile(strPath, finder.GetFileName(), "", bIsTextFile);
}
I don't get it.
-
August 5th, 2014, 01:15 AM
#8
Re: Problem with CFileFind
You are ignoring using _T() macro. Why? Is your build an ANSI one?
Did you debug your code?
Victor Nijegorodov
-
August 5th, 2014, 09:13 AM
#9
Re: Problem with CFileFind
Eventually figured out why the function was only finding directories but not files.
This loop structure works as expected:
Code:
if (finder.FindFile(strWildCard))
{
while (bWorking)
{
bWorking = finder.FindNextFile() == TRUE;
.
.
}
}
This loop structure screws it up:
Code:
if (finder.FindFile(strWildCard))
{
while (finder.FindNextFile())
{
.
.
}
}
Buggered if I can comprehend how this loop structure screws up FindNextFile()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|