Problem in adding new images ait folder from a selected folder

M

madhu

Hi all
I have a problem in this code which deletes all the prvious folders. If
you have any idea please give it. Thanks in advance.

Madhukar Arvind Kumar


void CHtmlGeneratorDlg::OnAdd()
{
// TODO: Add your control notification handler code here
/* HTREEITEM hItem = m_FolderTree.GetSelectedItem();
CString strItemText = m_FolderTree.GetItemText(hItem);
*/
CString szFilter = "Picture Files (*.*)|*.*||";
CFileDialog fd(TRUE, NULL, NULL, OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT, szFilter, NULL);

if (fd.DoModal() != IDOK) return;

// CString file = fd.GetFileTitle();

CString str = fd.GetPathName();

str.TrimRight(fd.GetFileName());
str.TrimRight("\\");

DoScan(str);
}

unsigned __int64 CHtmlGeneratorDlg::DoScan(const char *pszPath)
{
// save the root for "get path to node"
CString m_csPathRoot = pszPath;

//m_FolderTree.DeleteAllItems();
HTREEITEM hRoot = m_FolderTree.InsertItem(pszPath, 0, 0, TVI_ROOT,
TVI_LAST);

unsigned __int64 nSize = ScanDirectory(hRoot, pszPath);

return(nSize);
}

// scan one directory and collect the sizes of its files
// m_MYTreeCtrl is the tree ctrl in the dialog
unsigned __int64 CHtmlGeneratorDlg::ScanDirectory(HTREEITEM hDir, const
char *pszPath)
{
HANDLE hFind;
WIN32_FIND_DATA fd;
unsigned __int64 nSize = 0;

// look for all files in this directory
CString cs = pszPath;
if (cs.Right(1) != "\\")
cs += "\\";
cs += "*.*";

bool bHasSubdirs = false;

if ((hFind = ::FindFirstFile((LPCTSTR) cs, &fd)) !=
INVALID_HANDLE_VALUE)
{
do
{
// if this entry is not a directory, add the file size to the
running total
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
CString csFile = pszPath;
if (csFile.Right(1) != "\\")
csFile += "\\";
csFile += fd.cFileName;

unsigned __int64 nFileSize = fd.nFileSizeHigh;
nFileSize <<= 32;
nFileSize |= fd.nFileSizeLow;
nSize += nFileSize;
}

// but if it is a directory, except for . and ..
// then...
else if (strcmp(fd.cFileName, ".") != 0 && strcmp(fd.cFileName,
"..") != 0)
{
// add an entry to the tree for this directory
HTREEITEM hBranch = m_FolderTree.InsertItem(fd.cFileName, hDir);

// get the full path to this directory
CString csBranch = pszPath;
if (csBranch.Right(1) != "\\")
csBranch += "\\";
csBranch += fd.cFileName;

// and call this routine recursively to get the size of all that
// directory's contents (including, recursively, directories it
contains)
unsigned __int64 nBranchSize = ScanDirectory(hBranch,
LPCTSTR(csBranch));
nSize += nBranchSize;
bHasSubdirs = true;
}
} while :):FindNextFile(hFind, &fd));
::FindClose(hFind);
}

// get the name, but not the path of this directory
char szName[_MAX_PATH];
_splitpath(pszPath, NULL, NULL, szName, NULL);
char buff[1024];

// append the total contents size to the name
FormatSizeVal(buff, (nSize + 1023) / 1024);
sprintf(buff + strlen(buff), " %s", (szName[0] == '\0') ? pszPath :
szName);

// set the tree entry's displayed text
m_FolderTree.SetItem(hDir, TVIF_TEXT, buff, 0, 0, 0, 0, 0);
// and set the item data to the size, which will be used to sort by
size
m_FolderTree.SetItemData(hDir, (DWORD) (nSize / 1024));

return nSize;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top