Is there an async version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet?

前端 未结 7 2147
北荒
北荒 2020-12-08 06:50

Is there an asynchronous version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet? I\'d like to use them in an F# async block, and it\'d be nice to have a ver

7条回答
  •  没有蜡笔的小新
    2020-12-08 07:07

    This may be considered a bit of a hack, but you might consider using the UWP StorageFolder API.

    C# example (though F# is probably just as easy):

    using Windows.Storage;
    
    ...
    
    var folder = await StorageFolder.GetFolderFromPathAsync(path);
    var files = await folder.GetFilesAsync();
    var folders = await folder.GetFoldersAsync();
    

    You can easily consume these from traditional .NET desktop and console applications by using the UWP for Desktop library by Lucian Wischik (of Microsoft).

    Install-Package UwpDesktop
    

提交回复
热议问题