using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace vcsFNAME { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //------------------------------------------------------------------- private void Form1_Load(object sender, EventArgs e) { label1.Text = "拡張子入力"; label2.Text = "フォルダパス"; label3.Text = "ファイル名"; textBox1.Text = "txt"; textBox2.Text = ""; listBox1.Text = ""; } //------------------------------------------------------------------- private void toolStripButton1_Click(object sender, EventArgs e) { string dir = ""; string ext = "*." + textBox1.Text; //************************************************************************** //選択したフォルダ内の,textBox1に入力された拡張子のファイル名を //listBoxに列挙する //************************************************************************** listBox1.Items.Clear(); folderBrowserDialog1.Description = "フォルダを選択してください"; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { dir = folderBrowserDialog1.SelectedPath; } textBox2.Text = dir; foreach (string fname in System.IO.Directory.GetFiles(dir, ext)) { listBox1.Items.Add(System.IO.Path.GetFileName(fname)); } } //------------------------------------------------------------------- private void toolStripButton2_Click(object sender, EventArgs e) { System.IO.StreamWriter sw; string fnameW=""; int i; string dat; //************************************************************************** //textBox2に掲示されているフォルダ名,ファイル数,listBoxに列挙された //ファイル名を,指定ファイルに書き出す //************************************************************************** saveFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { fnameW = saveFileDialog1.FileName; } //データ書き込み sw = new System.IO.StreamWriter(fnameW, false, System.Text.Encoding.Default); dat = textBox2.Text + "," + listBox1.Items.Count.ToString(); sw.WriteLine(dat); for (i = 0; i <= listBox1.Items.Count-1; i++) { dat = listBox1.Items[i].ToString(); sw.WriteLine(dat); } sw.Close(); } //------------------------------------------------------------------- } }