Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Using: Scripting.FileSystemObject
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using: Scripting.FileSystemObject

 Post Reply Post Reply
Author
Nathan View Drop Down
Groupie
Groupie


Joined: 08 January 2002
Location: Greece
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nathan Quote  Post ReplyReply Direct Link To This Post Topic: Using: Scripting.FileSystemObject
    Posted: 19 May 2004 at 2:19pm

I am trying to list the contents of each folder using the following code. It works fine, but I would like to be able to access certain elements of oFolder.Files (see code below). Is this created as an array - if so, how could I list for example file 50-100 only?

Thanks - Nathan

Set oFSO = CreateObject("Scripting.FileSystemObject")

CurrentPath = Server.MapPath("/message_boards/posts/")

Set oFolder = oFSO.GetFolder(CurrentPath)
Set oFolderContents = oFolder.Files

For Each oFileItem in oFolder.Files

        witeout file name

next

Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2004 at 8:26pm

Don't think you can index it as in the past, I've seen routines to load the filelist into an array. For your situation, you may want to try something like this

Quote Set oFSO = CreateObject("Scripting.FileSystemObject")

CurrentPath = Server.MapPath("/message_boards/posts/")
Set oFolder = oFSO.GetFolder(CurrentPath)
Set oFolderContents = oFolder.Files

dim i
i = 0
For Each File in oFolder.Files
     i = i+1
     If i > 49 and i < 101 then
          Response.Write file.Name  & "<br />"
     end if
next

Set oFolder = Nothing
Set oFolderContents = Nothing
Set oFSO = Nothing

You'd probably want to check oFolderContents.count to make sure it was =/> than 50 and =/< 100 before doing the loop. - something like:

Quote Dim starti
Dim endi
If oFolderContents.count < 50 then
    starti = oFolderContents.count
else
    starti = 49
End If
If oFolderContents.count < 100 then 
    endi = oFolderContents.count
Else
    endi = 101
End If

Then in the For loop, change 49 and 101 to starti and endi respectively.



Edited by dpyers

Lead me not into temptation... I know the short cut, follow me.
Back to Top
Nathan View Drop Down
Groupie
Groupie


Joined: 08 January 2002
Location: Greece
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nathan Quote  Post ReplyReply Direct Link To This Post Posted: 20 May 2004 at 3:03pm

Perfect - thanks for that DP - exactly what I needed.

Cheers

Nathan

www.agni.gr

 

Back to Top
Nathan View Drop Down
Groupie
Groupie


Joined: 08 January 2002
Location: Greece
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nathan Quote  Post ReplyReply Direct Link To This Post Posted: 23 May 2004 at 9:12am

I have just run into a  small problem. The files are always sorted Alphabetically whereas I need them sorted with the latest first. Is there a way of doing this?

Thanks again.

Nathan

 

Set oFSO = CreateObject("Scripting.FileSystemObject")

CurrentPath = Server.MapPath("/message_boards/posts/")
Set oFolder = oFSO.GetFolder(CurrentPath)
Set oFolderContents = oFolder.Files

Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 23 May 2004 at 10:54am

There's no direct way to sort using FSO. The two indiect ways that are often used are to put the info into an array and sort the array - for dates, you'll need a two dimensional array, or put the info into a recordset and sort the record set.

You also have to figure out which FSO date you want to use. for an FSO File object, you have:
    .DateCreated
  .DateLastModified
  .DateLastAccessed

AspFaqs had some tutorials on array sorting. A google for asp fso sort would turn up more.


Lead me not into temptation... I know the short cut, follow me.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.