VB.NET / C# 遍历列出目录下所有文件
VB.NET / C# 遍历列出目录下所有文件
VB 代码
1 2 3 4 5 | Dim di As New DirectoryInfo("c:\temp") Dim info As FileSystemInfo For Each info In di.GetFiles System.IO.File.AppendAllText("c:\temp\test.txt", info.Name & vbCrLf) Next |
C# 代码
1 2 3 4 | DirectoryInfo TheFolder = new DirectoryInfo(@"c:\temp"); FileInfo[] fileInfo = TheFolder.GetFiles(); foreach (FileInfo NextFile in fileInfo) System.IO.File.AppendAllText(@"c:\temp\test.txt", NextFile.Name + "\r\n"); |