?
Solved

Sort a folder list retreived from FileSystemObject in reverse file date order.

Posted on 2005-04-18
3
Medium Priority
?
1,560 Views
Last Modified: 2011-10-03
Here is a snip of my current code.  Currently, the folder list is sorted alphabetacly.
I want objFolderContents to be sorted in reverse file date order(newest folder at the top)

Set objFSO = CreateObject("Scripting.FileSystemObject")
strPathInfo = baseDir & "\users\" & gp
Set objFolder = objFSO.GetFolder(strPathInfo)
Set objFolderContents = objFolder.SubFolders
'Run a loop through the directory list
For each FolderItem In objFolderContents

I have found several examples of sorting in ASP but I'm having a lot of trouble getting them to work.  Is it because I am using a "set object"?

Or maybe is it possible to ask FileSystemObject for the list sorted the way I want?

I need an example that will work with my code.




0
Comment
Question by:stanstan123
3 Comments
 
LVL 8

Accepted Solution

by:
anthonywjones66 earned 100 total points
ID: 13813566
Replace:-

For each FolderItem In objFolderContents

With:-

Dim i
Dim aoFolders

i = objFolder.SubFolders.count -1
ReDim aoFolders(i)

For each FolderItem in objFolder.SubFolders
      Set aoFolders(i) = FolderItem
      i = i - 1
Next

For Each FolderItem In aoFolders
'The rest of you code here.

aoFolders is array of folder objects held in reverse order.

Anthony.

0
 
LVL 7

Assisted Solution

by:Garve
Garve earned 50 total points
ID: 13813573
The short answer is that you can't sort the files using the FSO - damn shame!

The following links give examples of placing the files in an array and then sorting that.
www.experts-exchange.com/Web/Web_Languages/ASP/Q_20025270.html
www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=118

You can also use javascript to sort them, which would allow the user to choose whether they are sorted by date, size or alphabetically.
www.mattkruse.com/javascript/sorttable/index.html

Finally of course, if you only have a few files which never change, you could name them 01file.txt, 02file.txt etc in the order you want.

0
 
LVL 9

Assisted Solution

by:AlfaNoMore
AlfaNoMore earned 100 total points
ID: 13814347
For total flexibility, you should place them inside a Recordset object, and then use the .sort method that is part of that object:

Dim objFilesRS

Set objFilesRS = Server.CreateObject("ADODB.Recordset")
objFilesRS.Open()

objFilesRS.Fields.Append "FileName", adVarchar, 255
objFilesRS.Fields.Append "dateCreated" adDate

For Each file in objFSO

    objFilesRS.Add
    objFilesRS.Fields("FileName").Value = file.Name
    objFilesRS.Fields("dateCreated").Value = file.dateCreated
    objFilesRS.Update
   
Next

objFilesRS.Sort = "dateCreated DESC"

This is just a quick example, the following is much more thorough:


http://www.roubaixinteractive.com/PlayGround/FSO/Sort_Folder_Contents.asp
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question