/// <summary> /// Xoa tat ca cac tap tin va thu muc con ben trong thu muc strFolder, /// va ca thu muc strFolder tren FTP server /// Tham so: /// strFolder: ten thu muc muon xoa /// Tra ve: /// true: thanh cong /// false: that bai /// </summary> public bool DeleteFolder(String strFolder) { bool flag = _DeleteFolder(strFolder); return(flag && CWinINet.FtpRemoveDirectory(m_HConnect, strFolder)); }
/// <summary> /// Xoa tat ca cac tap tin va thu muc con ben trong thu muc strFolder /// tren FTP server /// Tham so: /// strFolder: ten thu muc muon xoa /// </summary> private bool _DeleteFolder(String strFolder) { StringBuilder szPath = new StringBuilder(256); uint uiLen = 256; WIN32_FIND_DATA FindFileData = new WIN32_FIND_DATA(); IntPtr hFindFile; if (CWinINet.FtpSetCurrentDirectory(m_HConnect, strFolder) == false) { return(false); } hFindFile = CWinINet.FtpFindFirstFile(m_HConnect, null, FindFileData, CWinINet.INTERNET_FLAG_RELOAD, 0); if (hFindFile.ToPointer() != null) { // Xoa tat ca cac tap tin if (!((FindFileData.dwFileAttributes & FileAttribute.FILE_ATTRIBUTE_DIRECTORY) == FileAttribute.FILE_ATTRIBUTE_DIRECTORY)) { if (CWinINet.FtpDeleteFile(m_HConnect, FindFileData.cFileName) == false) { return(false); } } while (CWinINet.InternetFindNextFile(hFindFile, FindFileData)) { if (!((FindFileData.dwFileAttributes & FileAttribute.FILE_ATTRIBUTE_DIRECTORY) == FileAttribute.FILE_ATTRIBUTE_DIRECTORY)) { if (!CWinINet.FtpDeleteFile(m_HConnect, FindFileData.cFileName)) { return(false); } } } CWinINet.InternetCloseHandle(hFindFile); // Xoa tat ca cac thu muc do { hFindFile = CWinINet.FtpFindFirstFile(m_HConnect, null, FindFileData, CWinINet.INTERNET_FLAG_RELOAD, 0); if (hFindFile.ToPointer() != null) { CWinINet.InternetFindNextFile(hFindFile, FindFileData); // Bo qua thu muc ".." if (CWinINet.InternetFindNextFile(hFindFile, FindFileData)) { CWinINet.InternetCloseHandle(hFindFile); return(_DeleteFolder(FindFileData.cFileName)); if (!CWinINet.FtpRemoveDirectory(m_HConnect, FindFileData.cFileName)) { return(false); } } else { CWinINet.InternetCloseHandle(hFindFile); break; } } else { break; } }while (true); // Tra ve thu muc hien hanh uiLen = 256; if (CWinINet.FtpGetCurrentDirectory(m_HConnect, szPath, ref uiLen) == false) { return(false); } if (CWinINet.FtpSetCurrentDirectory(m_HConnect, szPath.ToString() + "//..") == false) { return(false); } } return(true); }