前一段時間,寫個程序,要創(chuàng)建一個多級目錄。MFC中的CreateDirectory()函數(shù)只能夠創(chuàng)建一級目錄,所以我就編了個創(chuàng)建多級目錄的函數(shù)。
函數(shù)很簡單,直接調(diào)用就可以了。
函數(shù)說明:
入口:要創(chuàng)建的目錄,CString類型
出口:BOOL類型,true 成功,false 失敗。
代碼如下:
CreateMuliteCategory(CString FilePath)
{
CString Tempstr,dir;
Tempstr="";
int index=Tempstr.Find(’’);
while(!SetCurrentDirectory(FilePath))//ÅжÏÎļþ¼ÐÊÇ·ñ´æÔÚ
{
index ++;
while(’’ != FilePath.GetAt(index))
{
index ++;
}
CString s;
s.Format("%d",index);
Tempstr = FilePath.Left(index);//µÃµ½²¿·Ö·¾¶
CreateDirectory(Tempstr,NULL);
}
if(!SetCurrentDirectory(FilePath))
{
MessageBox("Îļþ¼Ð´´½¨Ê§°Ü!");
return false;
}
return true;
}
說明:函數(shù)沒有采用異常處理,可以根據(jù)需要自行修改。此函數(shù)只是提供了一個解決辦法。
函數(shù)很簡單,直接調(diào)用就可以了。
函數(shù)說明:
入口:要創(chuàng)建的目錄,CString類型
出口:BOOL類型,true 成功,false 失敗。
代碼如下:
CreateMuliteCategory(CString FilePath)
{
CString Tempstr,dir;
Tempstr="";
int index=Tempstr.Find(’’);
while(!SetCurrentDirectory(FilePath))//ÅжÏÎļþ¼ÐÊÇ·ñ´æÔÚ
{
index ++;
while(’’ != FilePath.GetAt(index))
{
index ++;
}
CString s;
s.Format("%d",index);
Tempstr = FilePath.Left(index);//µÃµ½²¿·Ö·¾¶
CreateDirectory(Tempstr,NULL);
}
if(!SetCurrentDirectory(FilePath))
{
MessageBox("Îļþ¼Ð´´½¨Ê§°Ü!");
return false;
}
return true;
}
說明:函數(shù)沒有采用異常處理,可以根據(jù)需要自行修改。此函數(shù)只是提供了一個解決辦法。