Effective file search solution in UWP

123244 140 Reputation points
2024-07-25T15:52:39.7766667+00:00

Hi, I need to search for files based on their type, creation date, and size (something like in windows). What are the options for an efficient search?

I tried to use the Storage API, but the search is quite slow, in turn, System.IO can access folders to which the user does not have permission, so often the search is interrupted by “Access denied” (for example, System.IO can access “C:\System Volume Information”, which is not desirable, since the user does not have access to such system files).

Developer technologies Universal Windows Platform (UWP)
Windows for business Windows Client for IT Pros User experience Other
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2024-07-25T17:56:45.54+00:00

    see Directory.EnumerateFiles. It has ignore no access files:

    var folder = @"c:\code";
    var match = "*.cs";
    var maxSize = 100;
    var filePaths = Directory.EnumerateFiles(folder, match, new EnumerationOptions
    {
        IgnoreInaccessible = true,
        RecurseSubdirectories = true
    }).Where(f =>
    {
        var fileInfo = new FileInfo(f);
        return fileInfo.Length < maxSize;
    });
    

    https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=net-8.0

    note: the windows file system is just not fast at searching for files.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.