开发者

How to paginate a list a files in a directory in asp?

We're using folder = objFSO.GetFolder(<path>) to get a list of files with a directory.

We then For Each over the folder.Files array to output the list of filenames.

We've got to a point where there are thousands of files in the folder and its quite slow so we want to add some pagination to the screen. So to all show 500 files at a time. I have no idea if this is even possible and all Google searches haven't helped.

Could anyone开发者_运维百科 point me in the right direction?


Firstly, regarding the listing of the files, can you get the listing and persist (cache) the result somewhere to speed up repeated access? This is a method we use in .NET when getting large listings of files (we're using ASP.NET Web Pages so we just use WebCache.Set, but I imagine you could write it to a text file if you needed to).

I see some anecdotal evidence here that FSO is quite slow when listing large numbers of files:

One consideration not addressed is speed. I had a small VB app which used FileSystemObject to loop through files in a folder. It took approx. 5-7 minutes just to walk through every file in a given folder (approx. 2200 files). When I switched to using the DIR() command, I could walk the files in about 6-10 seconds. There are limitations to DIR() as well, but the speed factor was a huge consideration which went against FileSystemObject.

Obviously once you have the listing you would loop through them 500 at a time with an offset / page size

EDIT: I include an example on how to use WScript.Shell to do this from a couple of aspfaq.com articles I found (1 | 2)

Set objWShell = CreateObject("WScript.Shell") 
Set objCmd = objWShell.Exec("%COMSPEC% /C dir c:\") 
strPResult = objCmd.StdOut.Readall() 


I wrote an online file browser a few years ago (available here), and found that it was reading the file sizes that slowed down file listing with FSO. As soon as I skipped that, then listing went lightning fast.

For pagination, I would recommend creating a 'disconnected' ado recordset out of the file names, and then use that for the actual navigation of names... then you've got pagination built in... as well as sorting and searching. Let me know if you're interested in a code example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜