I/O流。简单利用File.copy

首次在博客上发表文章,其中多有不足。

在windows窗口中建立的程序!

 

 

 public partial class Form1 : Form   

  {     

    public   Form1()      

   {            

InitializeComponent();     

    }

 

        private void Form1_Load(object sender, EventArgs e)      

   {            

//首先将我的音乐文件付给Listbox1中!            

//我们先将路径连接起来再查看文件夹里的音乐

            string lj = "D:\\Kugou";     

        //Directory.Exists(lj);      

       string[]  yu=Directory.GetFiles(lj);     

        foreach (var ii in yu)    

         {            

     listBox1.Items.Add(ii);    

                     }

        }       

 

        private void textBox1_TextChanged(object sender, EventArgs e)    

     {        

     listBox2.Items.Clear();        

     string p = textBox1.Text.Trim();        

     if (Directory.Exists(p))   

          {           

      //获取需要路径       

          string[] xy = Directory.GetDirectories(p);         

        foreach (var l in xy)           

      {

                    listBox2.Items.Add(l);

                }               

            }          

        }      

   public void ZBDY()

        {             

      string aa = textBox1.Text;  

               string bb =listBox2.Text;

                if (string.IsNullOrEmpty(aa) | string.IsNullOrEmpty(bb))   

              {            

         MessageBox.Show("请输入正确的路径!");   

              }            

     else               

  {                 

 

    //查看音乐文件是否被选中!

                    string xyu = listBox1.Text;

                    if (string.IsNullOrEmpty(xyu))         

            {                       

  MessageBox.Show("请选择音乐文件!");    

                     listBox1.Focus();   

                      return;             

        }                  

   else            

         {               

          string MYMU = (string)listBox1.SelectedItem;  

                       if (File.Exists(MYMU))    

                     {                           

  string name = Path.GetFileName(MYMU);         

                    File.Copy(MYMU, bb+"\\"+name, true);

                        }

                    }           

      }        

}

     

        private void button3_Click(object sender, EventArgs e)   

      {           

  ZBDY();       

  }

        private void button1_Click(object sender, EventArgs e)

        {      

       listBox1.Items.Clear();    

         string lj = "D:\\Kugou";       

                 string[] yu = Directory.GetFiles(lj);      

       foreach (var ii in yu)           

  {             

    listBox1.Items.Add(ii);

            }      

   }

           }

posted on 2012-06-14 15:49  枫叶㈱≌海】  阅读(166)  评论(0编辑  收藏  举报

导航