文件夹中最新创建文件的获取

qq_27066101 2018-05-05 03:55:19
一个文件夹下,有很多jpg文件,他们文件名为1.jpg,2.jpg,3.jpg,。。。。,根据创建时间,序号不断增大,而且文件数量还在持续不断地增加中。
怎么通过C++编程来确定当前时间下,最新创建的那个文件(或者序号最大的那个文件),并显示文件名称,精确度在毫秒级。
...全文
879 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_27066101 2018-05-07
  • 打赏
  • 举报
回复
谢谢大家给的建议
titan_ysl 2018-05-06
  • 打赏
  • 举报
回复
刚好我以前有写过类似的,现在贴出来,你改下就能用。 UnicodeString wjmLX; //文件名类型 wjmLX=wjmlujing; //wjmlujing 你要搜索的文件所在的路径 ListBox1->Items->BeginUpdate();//ListBox1是事先在窗体上放置的列表盒。 ListBox1->Clear(); TSearchRec sr; int iAttributes = 0; iAttributes |= faReadOnly; iAttributes |= faHidden; iAttributes |= faSysFile; // iAttributes |= faVolumeID; // iAttributes |= faDirectory; // iAttributes = faAnyFile; iAttributes |= faArchive; TStringList* MyList; MyList = new TStringList(); MyList->Clear(); UnicodeString lszc; wjmLX+="*.jpg"; //"*.*"; if(FindFirst(wjmLX, iAttributes, sr) == 0) { do { if ((sr.Attr & iAttributes) == sr.Attr) { lszc=sr.TimeStamp.FormatString("yyyymmddhhnnsszzz"); //在文件名的前面加上文件的建立时间 lszc+=sr.Name; MyList->Add(lszc); } } while (FindNext(sr) == 0); FindClose(sr); } MyList->Sorted = false; MyList->CaseSensitive=true; MyList->Sorted=true; //列表的文件名按文件的建立时间排序 int cd; for(int i=0;i<MyList->Count;i++) { lszc=MyList->Strings[i]; cd=MyList->Strings[i].Length(); ListBox1->Items->AddStrings(lszc.SubString1(18,cd-17)); //去掉文件名前的时间,放入列表盒中显示出来。 } ListBox1->Items->EndUpdate(); delete MyList;
ooolinux 2018-05-06
  • 打赏
  • 举报
回复
参考: C++ Builder在线程中监视文件夹变化 http://wmingyan.blog.163.com/blog/static/91267900201211582823522/
qq_27066101 2018-05-06
  • 打赏
  • 举报
回复
谢谢,我琢么琢么

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧