C#获取文件夹下的所有文件的文件名
String path = @"X:\xxx\xxx";
//第一种方法
var files = Directory.GetFiles(path, "*.txt");
foreach (var file in files)
Console.WriteLine(file);
//第二种方法
DirectoryInfo folder = new DirectoryInfo(path);
foreach (FileInfo file in folder.GetFiles("*.txt"))
{
Console.WriteLine(file.FullName);
}
C#获取局域网内共享文件夹
//远程服务器IP地址
string remoteServerIP = @"\\192.168.1.120";
//共享文件夹D:\\data 注意表示D盘,D$要大写
string remoteServerCatalog = @"\\192.168.1.120\技术部门\9.文档模板\"; //连接到共享目录 DirectoryInfo di = new DirectoryInfo(remoteServerCatalog); StringBuilder sb = new StringBuilder(); foreach (DirectoryInfo subDir in di.GetDirectories()) { sb.Append(subDir.Name + "\n\r");
}
Console.WriteLine(sb.ToString());