• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Search directory

How to query filename in a directory and return 10 filenames at a time?
sample
1-10 file
a user click next, provide the next 10 filename
0
VBdotnet2005
Asked:
VBdotnet2005
  • 3
  • 2
2 Solutions
 
DhaestCommented:
Easy example below

        Dim test As IEnumerable(Of String)

        test = getFiles(1, "c:\windows")

        test = getFiles(3, "c:\windows")
Private Function getFiles(ByRef page As Integer, ByRef directory As String) As IEnumerable(Of String)
        Dim Files = (From file In My.Computer.FileSystem.GetFiles(directory)
                    Order By file _
                    Select file).Skip((page - 1) * 10).Take(10)

        Return Files
    End Function

Open in new window

0
 
CuteBugCommented:
Hi VBDotNet2005,
         @Dhaest: Your function will call FileSystem.GetFiles each time the getFiles method is called. This might be CPU intensive.

          What you need to do is call the My,Computer.FileSystem.GetFiles() once and cache the result in you class.

          Then each time the next is pressed, use the skip and take methods to get the appropriate data.
0
 
DhaestCommented:
@CuteBug: I agree with your remark, but it was just an example to show the user of Skip() and Take() in linq
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
VBdotnet2005Author Commented:
Dhaest & CuteBug,

I have never used cache before. Is it like session, or collection? How can I use it in this case?
0
 
VBdotnet2005Author Commented:
Also, I am trying to convert C#.  Why error below?  
public IEnumerable<string> getFiles(ref int page, ref string directory)
        {
            var Files = (from file in directory
                         orderby file
                         select file).Skip((1 - 1) * 10).Take(1);

            return Files;  <<<<<   error
        }
0
 
VBdotnet2005Author Commented:
I am not sure what ByRef page As Integer is for. Could you explain a bit?
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now