获取目录的最新文件夹 [英] getting latest folder of directory

查看:80
本文介绍了获取目录的最新文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我没有收到最新的目录文件夹



这是我的代码



Why i am not getting latest folder of directory

This is my code

CString ClatestfoldernameDlg::FindLatestFolder(CString path)
{
	 CString Folder;
         CString LatestFolder = _T("D:\\xyz");
	 FILETIME newtime,oldtime;
	 WIN32_FIND_DATA ffd;
	 HANDLE hFind = INVALID_HANDLE_VALUE;

	 CString strWildcard(path);
	 strWildcard += _T("\\*");

	 // Find the first file in the directory.
	 hFind = FindFirstFile(strWildcard, &ffd);
	 FindNextFile(hFind, &ffd);
	 FindNextFile(hFind, &ffd);

	 //AfxMessageBox(ffd.cFileName);
	 oldtime=ffd.ftLastWriteTime;

	do
	{
      if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      {
		  newtime = ffd.ftLastWriteTime;
		  Folder = ffd.cFileName;
		  if(CompareFileTime(&newtime,&oldtime)==1)
		  {
				LatestFolder=Folder;
		  }
		  oldtime = newtime;
      }
   }
   while (FindNextFile(hFind, &ffd) != 0);

return LatestFolder;
}

推荐答案

首先,未声明 LatestFolder ,即使你返回这个对象。此外,当没有找到文件夹时,你没有为案件做好准备。此信息应足以修复您的代码。



-SA
First of all, LatestFolder is not declared, even though you return this object. Also, you don''t make provisions for the case when no folders are found. This information should be enough to fix your code.

—SA


这篇关于获取目录的最新文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆