最近寫了一個以時間為檔案夾名的連續建立檔案夾和子檔案夾的方法,createdirectory一次隻能建立一個檔案夾,不能直接建立其子檔案夾,是以需要多次調用。
systemtime sys;
getlocaltime( &sys );
cstring strfilepath;//檔案路徑
cstring strfolder;//檔案夾名稱
cstring strtemp;
strtemp.format("%d", sys.wyear);
strfolder = strtemp;
if(!pathfileexists(strfolder))//檔案夾不存在則建立
{
createdirectory(strfolder,null);
}
strtemp.format("\\%d", sys.wmonth);
strfolder += strtemp;
strtemp.format("\\%d", sys.wday);
執行上面代碼,就可以先建立名為2012的檔案夾,然後是如圖的檔案夾順序
。