基于c#将文件夹内的文件名导入文本文件

我在使用IrisSkin4.dll美化winform窗口时想将窗口皮肤导入一个文本文件中便于操作,所有窗口皮肤保存在Skins文件夹中,因此我写了如下的小程序,思路及代码代码都比较简单。(窗体应用程序)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace GetFileName
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            skinEngine1.SkinFile = "Skins//DiamondRed.ssk";
        }

        private void button1_Click(object sender, EventArgs e)  //对应界面上的RUN按钮
        {
            if (string.IsNullOrEmpty(Address.Text) || string.IsNullOrEmpty(FileType.Text) || string.IsNullOrEmpty(FileName.Text))
                return;
            else        //使用三个文本框分别储存文件夹的地址,输出文本文件的名字、后缀
            {
                FileStream fs = new FileStream(FileName.Text+  '.' + FileType.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sw = new StreamWriter(fs); // 创建写入流

                var files = Directory.GetFiles(Address.Text)
                foreach (var file in files)
                {
                    sw.WriteLine(Path.GetFileName(file));
                }
                sw.Close();
                MessageBox.Show("Succeed","result");
            }
        }
    }
}

运行截图

程序运行截图

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值