.NET 6 获取文件夹中的子文件夹名称
在 .NET 6 中,您可以使用 Directory.GetDirectories 方法来获取指定文件夹中的所有子文件夹的名称。以下是一个示例代码:
string folderPath = @"C:\YourFolderPath";
string[] subfolders = Directory.GetDirectories(folderPath);
foreach (string subfolder in subfolders)
{
string subfolderName = Path.GetFileName(subfolder);
Console.WriteLine(subfolderName);
}
上述代码将获取 C:\YourFolderPath 文件夹中的所有子文件夹名称,并在控制台中打印出来。您可以根据需要修改 folderPath 变量以指定您想要获取子文件夹名称的文件夹路径。
原文地址: https://www.cveoy.top/t/topic/qk1R 著作权归作者所有。请勿转载和采集!