Ejemplo n.º 1
0
BOOL FileUtils::rmDir(string dirName)
{
	char sTempFileFind[MAX_PATH] = "";
	sprintf_s(sTempFileFind, "%s\\*.*", dirName.c_str());
	
	CFileFind tempFind;
	BOOL isFinded = tempFind.FindFile(sTempFileFind);
	while (isFinded) {
		isFinded = tempFind.FindNextFile();
		/*
		 * 跳过 每个文件夹下面都有的两个特殊子文件夹:
		 *	(1) .  表示本文件夹自己
		 *	(2) .. 表示本文件夹的父文件夹
		 */
		if (!tempFind.IsDots()) {
			char tempFileOrDir[MAX_PATH] = "";
			sprintf_s(tempFileOrDir, "%s\\%s", dirName.c_str(), tempFind.GetFileName().GetBuffer(MAX_PATH));

			if (tempFind.IsReadOnly()) ::SetFileAttributes(tempFileOrDir, FILE_ATTRIBUTE_NORMAL);
			
			if (tempFind.IsDirectory()) rmDir(tempFileOrDir);
			else ::DeleteFile(tempFileOrDir);
		}
	}
	tempFind.Close();

	return ::RemoveDirectory(dirName.c_str());
}
Ejemplo n.º 2
0
/**
 * test if given file has read-only flag
 *
 * @param fileName		the file name
 * @return				TRUE if file exists and has read only flag,
 *						else FALSE 
 * @exception  
 * @see        
 */
BOOL CEFile::IsReadOnly(LPCTSTR fileName)
{
	CFileFind finder;
	BOOL bWorking = finder.FindFile(fileName);
	if (bWorking)
	{
		bWorking = finder.FindNextFile();
		return (finder.IsReadOnly());
	}
	else
		return FALSE;
}
//------------------------------------------------
// 파일의 리스트 및 각 파일에 대한 자세한 정보를 
// 함께 저장하게 됨
// data.h파일에 해당 구조체를 선언한다.
//--------------------------------------------------
void CMyExplorerDoc::SelectTreeViewFolder(CString strFullName)
{

	LIST_VIEW*	pListView;
	CFileFind	ff;

	// 사용자가 폴더를 선택할 때마다 파일 리스트를
	// 새로 업데이트 해야 함
	// 따라서 기존 정보를 모두 삭제한다.
	if (m_pFileList != NULL)
		RemoveAllFileList();

	m_pFileList = new CObList;

	SetCurrentPath(strFullName);
	strFullName += "*.*";

	if (ff.FindFile(strFullName) == TRUE)
	{
		BOOL	bFlag = TRUE;
		while(bFlag == TRUE)
		{
			bFlag = ff.FindNextFile();

			// 디렉토리 , 도트파일이면 다시 찾음 
			if (ff.IsDirectory() || ff.IsDots())
				continue;
			
			// 파일 정보를 알아내서LIST_VIEW 구조체에 
			// 저장한 후 
			// 그것을 모두 m_pFileList에 저장한다.
			pListView = new LIST_VIEW;
			InitListViewStruct(pListView);

			pListView->strName = ff.GetFileName();
			pListView->strPath = ff.GetFilePath();

			CString		strName = pListView->strName;
			CString		strExt = ff.GetFileTitle();

			int			nNum = strName.GetLength() - strExt.GetLength();

			if (nNum == 0)
				strExt = "";
			else
				strExt = strName.Right(nNum - 1);
			pListView->strKind = strExt + " 파일";
			pListView->dwFileSize = ff.GetLength();

			CTime	time;
			if (ff.GetCreationTime(time) == TRUE)
				pListView->tCreateTime = time;
			if (ff.GetLastAccessTime(time) == TRUE)
				pListView->tLastAccessTime = time;
			if (ff.GetLastWriteTime(time) == TRUE)
				pListView->tLastWriteTime = time;
			if (ff.IsHidden() == TRUE)
				pListView->bIsHidden = TRUE;
			if (ff.IsReadOnly() == TRUE)
				pListView->bIsReadOnly = TRUE;
			if (ff.IsArchived() == TRUE)
				pListView->bIsArchived = TRUE;
			if (ff.IsSystem() == TRUE)
				pListView->bIsSystem = TRUE;

			m_pFileList->AddTail((CObject*)pListView);
		}
	}
	ff.Close();

	//------------------------------
	m_pExpListView->SetFileList();
	//-------------------------------------
}