如何从列表框中将项目名称作为文件名? [英] How to make an item name from the listbox as a file name?

查看:71
本文介绍了如何从列表框中将项目名称作为文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家,



请帮我解决Visual Studio #C中的问题。

我正在创建重命名的实用程序多个文件的名称。

主要想法=用户打开包含文件的文件夹,并选择所需文件以在列表框中重命名。

可以通过在项目名称中搜索特殊单词(掩码MD)来执行选择。

我已经完成了过滤文件名称和更改名称的工作列表框。但我的问题 - 我无法复制项目的名称,并将这些项目保存为文件夹中的文件名称。

你有没有被观察到这样的问题?

请帮我解决问题。



我尝试了什么:



Dear Experts,

Please, help me resolve an issue in Visual Studio #C.
I am creating utility for renaming of names of multiple files.
Main idea = user opens the folder with files and selects required files for renaming in listbox.
Selection can be performed via searching by special words in names of items (masks "MD").
I have completed work at filtrating names of files and changing their names in listbox. But my problem - I cannot copy name of items and save these as names of files in folder.
Have you ever been observed such problem?
Please help me in solution.

What I have tried:

public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {

                listBox1.Items.Clear();

                string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
                string[] dirs = Directory.GetDirectories(folderBrowserDialog1.SelectedPath);
                SelectedPathText.Text = folderBrowserDialog1.SelectedPath;

                foreach (string file in files)
                {
                    listBox1.Items.Add(Path.GetFileName(file));
                }
                foreach (string dir in dirs)
                {
                    listBox1.Items.Add(Path.GetFileName(dir));
                    SelectedPathText.Text = Path.GetFileName(dir);
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            DialogResult result = MessageBox.Show("Are you sure ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.Yes)
            {
                timer1.Enabled = true;

                try
                {
                                
                    if (checkBox1.Checked)
                    {
                        int SelectedItem = listBox1.SelectedIndex;
                        listBox1.Items.RemoveAt(SelectedItem);
                        listBox1.Items.Insert(SelectedItem, (textBox_rig.Text + ("_" + (textBox_field.Text + ("_" + (textBox_pad.Text + ("_" + (textBox_well.Text + ("_" + (comboBox1.Text  +("_"   +("_"+ (comboBox2.Text + ("_" + ("MD"+ ("_"+ (textBox_start.Text + ("-" + (textBox_end.Text + (".PDF"))))))))))))))))))));
                        
                    }

                }
                catch
                {
                    Application.DoEvents();
                }

               
            }
        }

推荐答案

推荐方法是在重命名为新(空)文件夹时进行复制。



当确定一切正常时,则合并。看看专业人士是如何做到的:



IrfanView - 官方主页 - 其中一个全球最受欢迎的观众 [ ^ ]
The "recommended" approach is to copy while renaming to a new (empty) folder.

When certain all is ok, then "merge". See how the "pros" do it:

IrfanView - Official Homepage - One of the Most Popular Viewers Worldwide[^]

这篇关于如何从列表框中将项目名称作为文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆