none
이 소스가 어디가 잘못된 걸까요? Xiao_SJ_FileInfo RRS feed

  • 질문

  •  

    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;
    using System.IO;

    namespace hw10
    {
        public partial class Form1 : Form
        {
            public DirectoryInfo dinfo;
            public DirectoryInfo[] dir;
            public FileInfo C_file;
            public FileInfo P_file;
            public string C_fname;
            public int dir_count;
            public Form1()
            {
                InitializeComponent();
                dir_count = 0;
            }

     


            private void button1_Click(object sender, EventArgs e)
            {
              
                openFileDialog1.ShowDialog();
                dinfo = new DirectoryInfo(openFileDialog1.FileName);

                dinfo = dinfo.Parent;
                dir = dinfo.GetDirectories();
                dir_count = dir.Length + 1;
               
                listView1.Items.Clear();

                ListViewItem item = new ListViewItem("..", 0);
                item.SubItems.Add("");
                item.SubItems.Add("");
                item.SubItems.Add("");
                listView1.Items.Add(item);

                foreach (DirectoryInfo d in dir)
                {
                    ListViewItem item1 = new ListViewItem(d.Name.ToString(), 0);
                    item1.SubItems.Add(d.Attributes.ToString());
                    item1.SubItems.Add("");
                    item1.SubItems.Add(d.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                FileInfo[] files = dinfo.GetFiles();

                foreach (FileInfo f in files)
                {
                    ListViewItem item1 = new ListViewItem(f.Name.ToString(), 1);
                    item1.SubItems.Add(f.Attributes.ToString());
                    item1.SubItems.Add(f.Length.ToString());
                    item1.SubItems.Add(f.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                Text = dinfo.FullName.ToString();
            }

            private void listView1_Click(object sender, EventArgs e)
            {
                int index = listView1.FocusedItem.Index;

                if (index >= dir_count)
                {
                    return;
                }

                if (index != 0)
                {
                    dinfo = dir[index - 1];
                }
                else
                {
                    if (dinfo.Parent == null)
                    {
                        MessageBox.Show("루트 디렉토리 입니다.");
                        return;
                    }
                    dinfo = dinfo.Parent;
                }

                listView1.Items.Clear();

                ListViewItem item = new ListViewItem("..", 0);
                item.SubItems.Add("");
                item.SubItems.Add("");
                item.SubItems.Add("");
                listView1.Items.Add(item);

                dir = dinfo.GetDirectories();
                dir_count = dir.Length + 1;

                foreach (DirectoryInfo d in dir)
                {
                    ListViewItem item1 = new ListViewItem(d.Name.ToString(), 0);
                    item1.SubItems.Add(d.Attributes.ToString());
                    item1.SubItems.Add("");
                    item1.SubItems.Add(d.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                FileInfo[] files = dinfo.GetFiles();

                foreach (FileInfo f in files)
                {
                    ListViewItem item1 = new ListViewItem(f.Name.ToString(), 1);
                    item1.SubItems.Add(f.Attributes.ToString());
                    item1.SubItems.Add(f.Length.ToString());
                    item1.SubItems.Add(f.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                Text = dinfo.FullName.ToString();
            }

            private void 제거ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                FileInfo[] Delete_files = dinfo.GetFiles();
                string D_fname = dinfo.FullName.ToString() + "\\" +Delete_files[listView1.FocusedItem.Index - (dir.Length + 1)].Name.ToString();
               
                FileInfo D_file = new FileInfo(D_fname);
                D_file.Delete();
               

                listView1.Items.Clear();
                dir = dinfo.GetDirectories();
                dir_count = dir.Length + 1;

                listView1.Items.Clear();

                ListViewItem item = new ListViewItem("..", 0);
                item.SubItems.Add("");
                item.SubItems.Add("");
                item.SubItems.Add("");
                listView1.Items.Add(item);

                foreach (DirectoryInfo d in dir)
                {
                    ListViewItem item1 = new ListViewItem(d.Name.ToString(), 0);
                    item1.SubItems.Add(d.Attributes.ToString());
                    item1.SubItems.Add("");
                    item1.SubItems.Add(d.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                FileInfo[] files = dinfo.GetFiles();

                foreach (FileInfo f in files)
                {
                    ListViewItem item1 = new ListViewItem(f.Name.ToString(), 1);
                    item1.SubItems.Add(f.Attributes.ToString());
                    item1.SubItems.Add(f.Length.ToString());
                    item1.SubItems.Add(f.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                Text = dinfo.FullName.ToString();

            }

            private void 복사ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                FileInfo[] Copy_files = dinfo.GetFiles();
                C_fname = Copy_files[listView1.FocusedItem.Index - (dir.Length + 1)].Name.ToString();
                C_file = new FileInfo(dinfo.FullName.ToString()+ "\\" + C_fname);
            }

            private void 붙이기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
               FileInfo[] Check_files = dinfo.GetFiles();

               foreach (FileInfo f in Check_files)
               {
                   if (C_fname == f.Name)
                   {
                       MessageBox.Show("이미 파일이 있습니다.");
                       return;

                   }
               }
               
                FileInfo P_file = C_file.CopyTo(dinfo.FullName.ToString() + "\\" + C_fname , true);

                listView1.Items.Clear();
                dir = dinfo.GetDirectories();
                dir_count = dir.Length + 1;

                listView1.Items.Clear();

                ListViewItem item = new ListViewItem("..", 0);
                item.SubItems.Add("");
                item.SubItems.Add("");
                item.SubItems.Add("");
                listView1.Items.Add(item);

                foreach (DirectoryInfo d in dir)
                {
                    ListViewItem item1 = new ListViewItem(d.Name.ToString(), 0);
                    item1.SubItems.Add(d.Attributes.ToString());
                    item1.SubItems.Add("");
                    item1.SubItems.Add(d.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                FileInfo[] files = dinfo.GetFiles();

                foreach (FileInfo f in files)
                {
                    ListViewItem item1 = new ListViewItem(f.Name.ToString(), 1);
                    item1.SubItems.Add(f.Attributes.ToString());
                    item1.SubItems.Add(f.Length.ToString());
                    item1.SubItems.Add(f.CreationTime.ToString());
                    listView1.Items.Add(item1);
                }

                Text = dinfo.FullName.ToString();
            } 
        }
    }

    2008년 12월 8일 월요일 오후 12:44