?? folder.cpp
字號:
// Folder.cpp: implementation of the CFolder class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Folder.h"
IMPLEMENT_SERIAL(CFolder, CObject, VERSIONABLE_SCHEMA | 2000)
CFolder::CFolder()
{
m_pFather = NULL;//m_pFather為空
}
CFolder::CFolder(CString strFolderName, CFolder* pFather/*=NULL*/)//賦值m_strFolderName,m_pFather
{
m_strFolderName = strFolderName;
m_pFather = pFather;
}
CFolder::~CFolder()//析構CFolder時清空m_FolderList列表 (存放文件夾地址的列表)
{
CFolder* pFolder = NULL;
while (!m_FolderList.IsEmpty())//如果m_FolderList不為空
{
pFolder = (CFolder*)m_FolderList.RemoveHead();
delete pFolder;
}
}
BOOL CFolder::AddFileName(CString strFileName)//添加文件名函數
{
/** if(strFileName.IsEmpty())//如果strFileName為空則返回
{ASSERT(FALSE); return FALSE;}
CString g_strStockPath;//文件庫路徑
int nLen = strFileName.GetLength();//獲取文件名路徑字符長度
CString strTemp1(strFileName);
strTemp1.MakeUpper();//轉換為大寫字母
CString strTemp2(g_strStockPath);
strTemp2.MakeUpper();//轉換為大寫字母
int nPos = strTemp1.Find(strTemp2);
if(nPos != -1)//轉為相對路徑
strFileName = strFileName.Right(nLen - g_strStockPath.GetLength());**/
int nIndex = m_FileNameArray.GetSize();//獲取文件列表大小
CString strTemp;
while(nIndex--)//檢查文件名是否已經存在
{
strTemp = m_FileNameArray.GetAt(nIndex);
if(strTemp.CompareNoCase(strFileName) == 0)
{
ASSERT(FALSE);
return FALSE;//文件名存在
}
}
m_FileNameArray.Add(strFileName);//文件名增加到文件列表中
return TRUE;
}
BOOL CFolder::RemoveFileName(CString strFileName, BOOL bIsPathName/*=FALSE*/)//刪除文件名稱
{
ASSERT(!strFileName.IsEmpty());//如果strFileName為空則返回
CString strPathName = strFileName;//當前結點名稱
if(!bIsPathName)//如果不是路徑名稱
strPathName = FindFullFileName(strFileName);//strPathName=文件名路徑長度
CString g_strStockPath;//文件庫路徑
int nLen = strPathName.GetLength();//獲取文件名路徑長度
CString strTemp1(strPathName);
strTemp1.MakeUpper();//轉換為大寫字母
CString strTemp2(g_strStockPath);
strTemp2.MakeUpper();//轉換為大寫字母
int nPos = strTemp1.Find(strTemp2);
if(nPos != -1)
//絕對路徑轉為相對路徑
strPathName = strPathName.Right(nLen - g_strStockPath.GetLength());
int nIndex = m_FileNameArray.GetSize();//獲取文件列表大小
CString strTemp;
while(nIndex--)//檢查文件名是否存在
{
strTemp = m_FileNameArray.GetAt(nIndex);
if(strTemp.CompareNoCase(strPathName) == 0)//是否存在
{
m_FileNameArray.RemoveAt(nIndex);//從列表中刪除文件
return TRUE;
}
}
ASSERT(FALSE);
return FALSE;//文件名存在
}
CString CFolder::FindFullFileName(CString strFileName)//獲取文件完整路徑
{
CString strFullFileName;
int nIndex = m_FileNameArray.GetSize();//得到文件列表大小
while(nIndex--)
{
strFullFileName = m_FileNameArray.GetAt(nIndex);//獲取文件名稱
if(strFullFileName.Find(strFileName) != -1)//找到相應文件
{
CString g_strStockPath;//文件庫路徑
if(strFullFileName[1] != _T(':'))//第一個字符不是以“:”開頭
strFullFileName = g_strStockPath+strFullFileName;//相對路徑轉為絕對路徑
return strFullFileName;//返回文件絕對路徑
}
}
return CString("");
}
void CFolder::AddFolder(CFolder* pFolder)//增加文件夾函數
{
ASSERT(pFolder != NULL);//pFolder為空則返回
/**/ pFolder->m_pFather = this;
m_FolderList.AddTail(pFolder);//在m_FolderList中增加pFolder
}
void CFolder::RemoveFolder(CFolder* pFolder, BOOL bDelete/*=TRUE*/)//刪除文件夾
{
ASSERT(pFolder != NULL);
POSITION pos;
pos = m_FolderList.Find(pFolder);//找到文件夾在m_FolderList中的索引
if(!pos)
return;
m_FolderList.RemoveAt(pos);//刪除索引指針
if(bDelete)
delete pFolder;//釋放對象
}
void CFolder::Serialize(CArchive& ar)//序列化存取文件
{
m_FileNameArray.Serialize(ar);
m_FolderList.Serialize(ar);
if (ar.IsStoring())//存儲文件
{
ar << m_strFolderName;
}
else//打開文件
{
ar >> m_strFolderName;
CFolder* pFolder = NULL;
POSITION pos = m_FolderList.GetHeadPosition();//pos= m_FolderList的頭結點
while (pos != NULL)//
{
pFolder = (CFolder*)m_FolderList.GetNext(pos);//
pFolder->m_pFather = this;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -