列出文件夹中的所有文件 [英] list all the files in a folder
本文介绍了列出文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,出口
我遇到了困难.我想列出文件夹中的所有文件.假设:"D:\ bin".如何获得所有这些文件名并将其写入Excel文件?我无话可说.你的想法怎么样?提前致谢.我在这里使用C#.NET.在这种情况下或API可以调用任何方法吗?
关于
Hi exports,
I am facing a difficulty. I want to list all the files in a folder. Let''s say: "D:\bin". How can I get all these files names and write them to Excel files? I am no way to figure. How about your ideas? Thanks in Advance. I am using C#.NET here. Any methods to call in that case or API?
Regards
推荐答案
要获取文件列表:
To get a list of files :
string[] files = Directory.GetFiles(@"D:\bin", "*.*");
要写入Excel,请尝试使用类似以下的库: http://epplus.codeplex.com/ [
To write to Excel try using a library like : http://epplus.codeplex.com/[^]
简而言之:
要使用System.IO
命名空间中的.NET Framework方法和C#编程语言列出文件夹或目录中的所有文件,该框架在Directory类上提供了功能强大的方法,可以帮助您您列出文件系统上的文件.Directory.GetFiles
方法允许您获取文件名的字符串数组.
请参考:
C#Directory.GetFiles [ ^ ]
本示例说明如何从目录(包括子目录)获取文件名列表.您可以按特定的扩展名过滤列表.
从目录[C#]中获取文件 [
In short:
To list all the files in a folder or directory using the .NET Framework''s methods in theSystem.IO
namespace and the C# programming language, the framework provides powerful methods on the Directory class that can help you list files on the filesystem. TheDirectory.GetFiles
method allows you to get a string array of the file names.
Please refer:
C# Directory.GetFiles[^]
This example shows how to get list of file names from a directory (including subdirectories). You can filter the list by specific extension.
Get Files from Directory [C#][^]
嗨
查看项目
MP3-Rearrange
请参阅类RecursiveIO.那将搜索目录树.如果只想要指定的目录,请删除对方法subRecurse中的方法subRecurse的调用.
您可以重写ProcessFileName方法以写入以逗号分隔的文本文件,Excel可以轻松导入该文本文件.
最佳
约翰·奥伦特(John Orendt)
Hi
see project
MP3-Rearrange
See class RecursiveIO. That will search a directory tree. Remove the call to method subRecurse in method subRecurse if you want the specified directory only.
You can override method ProcessFileName to write to a comma separated text file which Excel can easily import.
Best
John Orendt
这篇关于列出文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文