Discussion:
Enumerate files in date order
(too old to reply)
unknown
2008-11-26 19:35:32 UTC
Permalink
Hi Folks,

The following snippet will let me enumerate files...

var fs = new ActiveXObject("Scripting.FileSystemObject");
var f = new Enumerator(fs.GetFolder(d).files);

for ( ; !f.atEnd(); f.moveNext())
{
:
}

How do I assert the order I want the files? Alphabetical by Name, Date of
Creation, Date of Last Access, you get the idea...

Thanks,

Chris.
Anthony Jones
2008-11-26 21:23:59 UTC
Permalink
Post by unknown
Hi Folks,
The following snippet will let me enumerate files...
var fs = new ActiveXObject("Scripting.FileSystemObject");
var f = new Enumerator(fs.GetFolder(d).files);
for ( ; !f.atEnd(); f.moveNext())
{
}
How do I assert the order I want the files? Alphabetical by Name, Date of
Creation, Date of Last Access, you get the idea...
You can't control the order the files are retrieved from the Files
collection (on an NTFS volume they will be in alphanumerical name order),
you need first dump them into an array then sort the array.

var fs = new ActiveXObject("Scripting.FileSystemObject");
var f = new Enumerator(fs.GetFolder(d).files);
var files = [];

for ( ; !f.atEnd(); f.moveNext())
files.push(f.item())

function propertyComparator(property)
{
return function(o1, o2)
{
return o1[property] < o2[property] ? -1 : (o1[property] ==
o2[property] ? 0 : 1)
}
}

files.sort(propertyComparator('DateLastModified'))

//now files is sorted in order of DateLastModified
--
Anthony Jones - MVP ASP/ASP.NET
Loading...