GetFiles and EnumerationOptions

Anonymous
2024-04-26T10:57:50.91+00:00

Hi

Question at top to avoid long scrolling below.

I have tried so many thing, downloading/installing many 'versions' (5,6,7,8,9) and have not had a single sucess in my trials trying to use (as below). In almost every case I only ever get 'not found' errors.

What do I need to install to make use of this?

public System.IO.FileInfo[] GetFiles (string searchPattern, System.IO.EnumerationOptions enumerationOptions);

from:

https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.getfiles?view=net-8.0#system-io-directoryinfo-getfiles(system-string-system-io-enumerationoptions)

which applies to:

.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9

My current version:

Microsoft Visual Studio Community 2022

Version 17.10.0 Preview 4.0

VisualStudio.17.Preview/17.10.0-pre.4.0+34814.14

Microsoft .NET Framework

Version 4.8.09032

Installed Version: Community

ASP.NET and Web Tools 17.10.319.52870

ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.10.319.52870

Azure App Service Tools v3.0.0

C# Tools 4.10.0-3.24211.4+e482b6e281d7db727fcb086ebbfae44dcba82c6d

C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

GitHub Copilot 0.2.860.47384

GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Microsoft JVM Debugger 1.0

Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.10.0

NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

TypeScript Tools 17.0.30327.2001

TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.10.0-3.24211.4+e482b6e281d7db727fcb086ebbfae44dcba82c6d

Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.10.0-beta.24172.5+8d852e43d35fdac96b1ba52e3bd4b35350035914

Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2

AI-assisted development for Visual Studio.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,389 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 49,251 Reputation points
    2024-04-26T14:12:27.26+00:00

    Please be more specific about your error. When do you get "not found"? Is this a compiler error or when you run your code? Since it seems code related then please post the code that isn't working.

    The method in question has been around a long time and the following simplistic example shows how to use it.

    var dir = new DirectoryInfo(@"C:\temp");
    
    var files = dir.GetFiles("*.txt", new EnumerationOptions() { MaxRecursionDepth = 2 });
    
    foreach (var  file in files)
    {
        Console.WriteLine(file);  
    };
    

    Note that if you're using .NET Standard 2.0 then you also need a using System.IO in your file.


  2. Bruce (SqlWork.com) 57,891 Reputation points
    2024-04-26T16:50:37.41+00:00

    to use that api, you need to create a .net 8 project. to run the sample in the link, create console app for windows, linux and macOs.

    if you are using .NET framework (windows) only, then you are using the wrong docs. use:

    https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.getfiles?view=netframework-4.8