| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1082 人关注过本帖
标题:如何显示不带路径的文件名
只看楼主 加入收藏
yuanwei568
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-11-20
结帖率:80%
收藏
 问题点数:0 回复次数:2 
如何显示不带路径的文件名
各位大侠:
    你们好,求助一个问题。我用openFileDialog打开了一些文件,但是在listBox1中显示的都带有路径的文件名,怎么样才能够把这些路径取消掉,不显示路径,直接显示文件名。谢谢各位了。我的代码如下
 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {   int i;
           Stream myStream;
         //  FileStream GetFile;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "D:\\岩性密度测井";
            openFileDialog1.Filter = "txtfiles(*.txt)|*.txt|inp文件(*.inp)|*.inp|All files(*,*)|*.*";
            openFileDialog1.FilterIndex=2;
            openFileDialog1.Multiselect = true;
            openFileDialog1.RestoreDirectory=true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                { myStream.Close(); }
                string[] str1 =openFileDialog1.FileNames;
                for (i = 0; i < str1.Length; i++)
                {
                   listBox1.Items.Add(str1[i]);
                }
            
            }

        }
搜索更多相关主题的帖子: 路径 文件名 
2009-09-30 23:49
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:0 
listBox1.Items.Add(str1[i].Substring(str1[i].LastIndexOf('\')));

试试吧

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-10-01 06:13
ljb851331689
Rank: 2
等 级:论坛游民
帖 子:25
专家分:39
注 册:2009-8-28
收藏
得分:0 
   int i;
            Stream myStream;
            //  FileStream GetFile;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "D:\\岩性密度测井";
            openFileDialog1.Filter = "txtfiles(*.txt)|*.txt|inp文件(*.inp)|*.inp|All files(*,*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.Multiselect = true;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                { myStream.Close(); }
                string[] str1 = openFileDialog1.FileNames;
 
                //for (i = 0; i < str1.Length; i++)
                //{
                //    listBox1.Items.Add(str1[i]);
                //}
 
 
                foreach (string mystring in openFileDialog1.FileNames)
                {
                    string op = mystring.Substring(mystring.LastIndexOf("\\") + 1);
 
                    this.listBox1.Items.Add(op);
                 
                 
                 
                }
 
            }
2009-10-03 09:30
快速回复:如何显示不带路径的文件名
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022502 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved