C# 获取文件夹里所有文件名的详细代码
作者:ou.cs 时间:2023-01-07 02:05:20
主要是这个方法
List<string> GetAllFileNames(string path,string pattern="*")
{
List<FileInfo> folder = new DirectoryInfo(path).GetFiles(pattern).ToList();
return folder.Select(x=>x.Name).ToList();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GetFileNames
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = @"D:\jdScript\jdpro-main";
textBox2.Text = "*.js";
}
string _outFileName = "aaaa.bat";
private void button1_Click(object sender, EventArgs e)
{
foreach (var fileName in GetAllFileNames(textBox1.Text))
{
richTextBox1.AppendText("node " + fileName + '\n');
}
OutputFile(textBox1.Text + "\"+ _outFileName, richTextBox1.Text);
}
void OutputFile(string strFilePath,string strContent)
{
StreamWriter swOut = new StreamWriter(strFilePath, false, Encoding.Default);
swOut.WriteLine(strContent);
swOut.Flush();
swOut.Close();
}
List<string> GetAllFileNames(string path,string pattern="*")
{
List<FileInfo> folder = new DirectoryInfo(path).GetFiles(pattern).ToList();
return folder.Select(x=>x.Name).ToList();
}
}
}
补充:C# 正则表达式分组查询
result[1] = "memory usage threshold: 80 %";
strResult = Regex.Match(result[1], @"(?<a>\d+)\s*%").Groups["a"].ToString();
分组的命名方式为:(?< groupname > exp) 捕获exp
来源:https://blog.csdn.net/weixin_44291381/article/details/124349994
标签:C#,获取,文件夹,文件名
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Opencv实现读取摄像头和视频数据
2023-07-16 15:19:58
Spring bean对象实例化实现过程图解
2023-01-02 07:32:13
![](https://img.aspxhome.com/file/2023/1/125501_0s.png)
Spring MVC入门_动力节点Java学院整理
2023-11-03 20:35:31
![](https://img.aspxhome.com/file/2023/3/58753_0s.jpg)
C#微信公众号开发 微信事件交互
2023-04-22 21:18:31
![](https://img.aspxhome.com/file/2023/7/91247_0s.png)
SpringMVC结合天气api实现天气查询
2021-06-01 16:56:41
![](https://img.aspxhome.com/file/2023/1/72321_0s.png)
详解Java设计模式编程中的中介者模式
2021-09-24 02:48:54
![](https://img.aspxhome.com/file/2023/9/78959_0s.jpg)
Java面试题冲刺第十八天--Spring框架3
2023-04-17 22:44:29
![](https://img.aspxhome.com/file/2023/4/96124_0s.jpg)
GSON实现Java对象的JSON序列化与反序列化的实例教程
2023-11-23 12:39:02
基于WPF实现简单的文件夹比较工具
2023-11-15 16:08:34
![](https://img.aspxhome.com/file/2023/6/74836_0s.png)
Java数据结构之链表实现(单向、双向链表及链表反转)
2021-10-17 18:04:25
![](https://img.aspxhome.com/file/2023/9/128849_0s.png)
基于C#解决库存扣减及订单创建时防止并发死锁的问题
2023-03-16 20:59:53
![](https://img.aspxhome.com/file/2023/1/92871_0s.png)
spring aop之链式调用的实现
2022-10-30 05:56:50
![](https://img.aspxhome.com/file/2023/4/84654_0s.png)
C#权限管理和设计浅谈
2023-10-09 07:14:45
Java线程Timer定时器用法详细总结
2022-02-16 23:11:54
RestTemplate在Spring或非Spring环境下使用精讲
2022-03-03 07:35:41
![](https://img.aspxhome.com/file/2023/0/122030_0s.png)
解析maven的用法和几个常用的命令(推荐)
2022-04-16 23:31:15
![](https://img.aspxhome.com/file/2023/4/87174_0s.jpg)
利用Jetpack Compose实现绘制五角星效果
2023-04-10 06:20:48
![](https://img.aspxhome.com/file/2023/7/137847_0s.png)
springMvc请求的跳转和传值的方法
2023-02-06 17:29:56
浅析Java中接口和抽象类的七大区别
2022-01-16 21:09:36
![](https://img.aspxhome.com/file/2023/6/76266_0s.png)
C++函数指针和回调函数使用解析
2022-11-16 21:01:15