Problem in adding new images ait folder from a selected folder

Discussion in 'C++' started by madhu, Oct 5, 2006.

  1. madhu

    madhu Guest

    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;
    }
    madhu, Oct 5, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    4
    Views:
    878
    Eliyahu Goldin
    Jan 4, 2005
  2. Iain
    Replies:
    3
    Views:
    914
  3. Nathan Sokalski
    Replies:
    0
    Views:
    593
    Nathan Sokalski
    Oct 5, 2008
  4. John
    Replies:
    5
    Views:
    969
    dorayme
    Mar 1, 2010
  5. mldardy
    Replies:
    0
    Views:
    950
    mldardy
    Sep 28, 2010
Loading...

Share This Page