[英]c# System.IO how do i find all the subfolders given a certain folder?
[英]A given folder (like C:\Random Folder), how can I find ALL the extensions and print them C#?
我已經搜索並發現只有如何獲得某個擴展名(如 txt。)。 我需要獲取所有擴展並將它們打印在控制台上。 這怎么可能?
var dir = new DirectoryInfo(@"C:\Random\");
var allExtensions = dir.EnumerateFiles().Select(f => f.Extension).Distinct();
foreach (string ext in allExtensions)
Console.WriteLine(ext);
如果您還想在子目錄中列出所有擴展,請使用此選項:
var allExtensions = dir.EnumerateFiles("*.*", SearchOption.AllDirectories)
.Select(f => f.Extension)
.Distinct();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.