Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to get the files in a folder in a specific order, you'll have to do it yourself. If you don't like the ADO recordset or using a sortable .NET collection, you can shell out (.Run, .Exec) and process the output of <code>dir /A:-D /B /O:D /T:C</code> (no folders, bare format (no header/summary), order:date, timefield:creation). </p> <p><strong>Update:</strong></p> <p>While I surely can show examples where the .Files collection delivered its elements ordered by name, Mr. Gates explicitly <a href="http://support.microsoft.com/kb/189751/en-us" rel="nofollow">says</a>:</p> <blockquote> <p>INFO: Limitations of the FileSystemObject ... Cannot sort file names from the files collection - you can iterate through the File objects in the Files collection to obtain a list of the files in a folder. However, the File objects are not sorted. You need to use a sort routine to sort the File objects in the Files collection.</p> </blockquote> <p>Minimalistic demo code that shows: You need a shell (%comspec%) if you want to use shell features - like <a href="http://elearning.algonquincollege.com/coursemat/viljoed/gis8746/concepts/dosbatch/advanced/intrin1.htm" rel="nofollow">intrinsic commands</a>:</p> <pre><code>Option Explicit Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject") Dim goWS : Set goWS = CreateObject("WScript.Shell") Dim csDir : csDir = "c:\temp" WScript.Quit demoSF() Function demoSF() demoSF = 0 Dim aDSOrd : aDSOrd = getDSOrd(csDir, "%comspec% /c dir /A:-D /B /O:D /T:C """ &amp; csDir &amp; """") Dim oFile For Each oFile In aDSOrd WScript.Echo oFile.DateCreated, oFile.Name Next End Function ' demoSF Function getDSOrd(sDir, sCmd) Dim dicTmp : Set dicTmp = CreateObject("Scripting.Dictionary") Dim oExec : Set oExec = goWS.Exec(sCmd) Do Until oExec.Stdout.AtEndOfStream dicTmp(goFS.GetFile(goFS.BuildPath(sDir, oExec.Stdout.ReadLine()))) = Empty Loop If Not oExec.Stderr.AtEndOfStream Then WScript.Echo "Error:", oExec.Stderr.ReadAll() End If getDSOrd = dicTmp.Keys() End Function </code></pre> <p>Output:</p> <pre><code>cscript 16895525.vbs 07.10.1998 15:31:34 TlbInf32.chm .. 09.10.2008 22:40:29 sqlce.sql 09.10.2008 22:40:29 gltsqlcopytest.sdf 05.11.2008 20:11:39 Vorfuehrung.class .. 28.03.2011 20:23:36 Program.cs . 01.10.2012 10:10:10 KyXHDe.chm </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload