主要是这个方法
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.Linphpq; ujavascriptsing 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 " + fiwww.devze.comleName + '\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 = Rege编程客栈x.Match(result[1], @"(?<a>\d+)\s*%").Groups["a"].ToStjsring();
分组的命名方式为:(?< groupname > exp) 捕获exp
到此这篇关于C# 获取文件夹里所有文件名的文章就介绍到这了,更多相关C# 获取文件夹文件名内容请搜索我们以前的文章或继续浏览下面开发者_JAVA学习的相关文章希望大家以后多多支持我们!
精彩评论