CString get_path()//获取当前程序工作的目录
{
TCHAR szFilePath[MAX_PATH];
DWORD dwFLen=::GetModuleFileName(_AtlBaseModule.GetModuleInstance(),szFilePath,MAX_PATH);
//其中_AtlBaseModule.GetModuleInstance()可以为null
CString sPath=szFilePath;
int i=sPath.ReverseFind('//');
if(i>0) sPath=sPath.Left(i);
return sPath;
}
int main()
{
CString strDir=get_path()+_T("//Torrents//*.*");
HANDLE hFind;
WIN32_FIND_DATA fd;
CString filename;
CString strTmp;
hFind=::FindFirstFile((LPCTSTR)strDir,&fd);
if(hFind==INVALID_HANDLE_VALUE) return 0;
do{
if(!strcmp(fd.cFileName,_T("."))||!strcmp(fd.cFileName,_T("..")))
continue;
if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
CString name=strDir+fd.cFileName;
}
filename=fd.cFileName;
int i=filename.Find(_T(".torrent"),0);
if(i!=-1)
{
strTmp=strDir+filename;
strTmp=get_path()+_T("//Torrents//DownloadTorrents.ini");
CString savepath;
::GetPrivateProfileString("DownLad_Torrents",strTmp,"c://secbt",savepath.GetBuffer(MAX_PATH),MAX_PATH,strTmp);
}
}while(::FindNextFile(hFind,&fd));
}