NET6 怎么获取文件夹里面的其他文件夹名
在.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
变量以指定您想要获取子文件夹名称的文件夹路径。

原文地址: http://www.cveoy.top/t/topic/iEqk 著作权归作者所有。请勿转载和采集!