FindAllFiles lazarus / 61-Beginners ---------------------------------------------------------------------- nugax · 2022-02-28 15:55 Using FindAllFiles, is there a way to order the files by date on disk? Right now, its opening them in random order (or maybe its opening them in filename order).. I cant tell? 1)Anyone know how it chooses which files to open first? 2) Anyone know how to force it to open files by filedate? Thanks, ---------------------------------------------------------------------- 440bx · 2022-02-28 16:10 the order the files will be reported in depends on the O/S.  the O/S will decide and it usually is in whatever order the O/S has indexed the files. if you need the files in a specific order, you need to sort them to be in that order yourself. HTH. ---------------------------------------------------------------------- nugax · 2022-02-28 16:30 Quote from: 440bx on February 28, 2022, 05:10:02 pmthe order the files will be reported in depends on the O/S.  the O/S will decide and it usually is in whatever order the O/S has indexed the files. if you need the files in a specific order, you need to sort them to be in that order yourself. HTH. - how would i sort them myself? ---------------------------------------------------------------------- AlexTP · 2022-02-28 16:34 You get the TStringList. It has the CustomSort() method. Give the sorting parameter there, which sorts like you need. ---------------------------------------------------------------------- Bart · 2022-02-28 17:59 AFAIK FindAllFiles does not return filedates in the list (TStrings) it returns. So, you cannot sort the list on the filedate directly. Using CustomSort, you can specify a compare function to use. In that compare function you can check the date of the filename. The drawback is that essentially you are asking the OS multiple times to give you the filedate for a given file. In ShellCtrls unit there is a helper function GetFilesInDir() which gives an example of how you could get the information at one go and do the sort withou re-querying the OS. Bart ---------------------------------------------------------------------- winni · 2022-02-28 18:57 Hi! Use the FileListBox from Tab "Misc". You can sort for name, size and date. Winni ---------------------------------------------------------------------- nugax · 2022-02-28 19:28 Quote from: winni on February 28, 2022, 07:57:37 pmHi! Use the FileListBox from Tab "Misc". You can sort for name, size and date. Winni using terminal. not gui. ---------------------------------------------------------------------- nugax · 2022-02-28 19:29 Where can I find shellctrls? I get a linking error if I just simply add it to my uses in the needed unit. Quote from: Bart on February 28, 2022, 06:59:05 pmAFAIK FindAllFiles does not return filedates in the list (TStrings) it returns. So, you cannot sort the list on the filedate directly. Using CustomSort, you can specify a compare function to use. In that compare function you can check the date of the filename. The drawback is that essentially you are asking the OS multiple times to give you the filedate for a given file. In ShellCtrls unit there is a helper function GetFilesInDir() which gives an example of how you could get the information at one go and do the sort withou re-querying the OS. Bart ---------------------------------------------------------------------- winni · 2022-02-28 20:58 Hi! TShellTreeview  --> Tab "Misc" TShellListview  --> Tab "Misc" Winni ---------------------------------------------------------------------- balazsszekely · 2022-03-01 07:22 @nugax QuoteWhere can I find shellctrls? I get a linking error if I just simply add it to my uses in the needed unit.You should add unit interface before ShellCtrls to avoid linking errors, but that's not the point. GetFilesInDir is in the implementation section of ShellCtrls, it's not available for outside units. What @Bart meant to say is that you should study how sorting is implemented in GetFilesInDir, or even better why don't you try to implement your TFileSearch class? ---------------------------------------------------------------------- Zvoni · 2022-03-01 08:30 Don't think GetFilesInDir is a good idea in this case, since it doesn't traverse sub-folders. In OP's case: If using FindAllFiles: Get your Filenames, run through the resulting StringList, collect the TimeStamps, throw them into the associated Object, sort All mentioned disadvantages not withstanding write your own FindFirst/FindNext: Advantage: The TSearchRec-Result already has all your information Disadvantage: you have to implement it yourself if you want to traverse sub-folders ---------------------------------------------------------------------- BobDog · 2022-03-06 13:07 Try this out. Shows all files in a given path sorted by date. If you want to hide the dates, but still sort 'em, see line 17. Then you could use tstringlist (or a method of your choice of course) to set them into an array maybe, I left that out. At the moment the results are held in an ansistring. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode delphi} uses  process,sysutils;    function dir(path:ansistring;flag:ansistring='s'):ansistring;  var ans:ansistring=' ';  begin  RunCommand('c:\windows\system32\cmd.exe', ['/c', 'dir /'+flag+' '+path], ans);  exit(ans);  end; vars:ansistring;begin  s:=dir(GetCurrentDir,'OD ');  //  'OD /b'  for dates not shownwriteln(s);writeln('Press enter to exit . . .');readln;end.