コード例 #1
0
ファイル: Form1.cs プロジェクト: wjf8882300/rename
 private ArrayList arrayListSort(ArrayList arraylist)
 {
     for (int i = 0; i < arraylist.Count; i++)
     {
         for (int j = arraylist.Count - 1; j > i; j--)
         {
             PinLv p1 = (PinLv)arraylist[j];
             PinLv p2 = (PinLv)arraylist[j - 1];
             if (p1.cout > p2.cout)
             {
                 PinLv p = new PinLv();
                 p            = (PinLv)arraylist[i];
                 arraylist[i] = arraylist[j];
                 arraylist[j] = p;
             }
         }
     }
     return(arraylist);
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: wjf8882300/rename
        private ArrayList Compare(ArrayList array)
        {
            ArrayList newarray = new ArrayList();
            ArrayList myarray  = new ArrayList();
            ArrayList temp     = new ArrayList();

            for (int i = 0; i < array.Count; i++)
            {
                ListViewItem listviewItem = (ListViewItem)array[i];
                string       str          = listviewItem.Text;
                try
                {
                    string before   = "";
                    string end      = "";
                    string filepath = strFilePath + "\\" + str;
                    //文件
                    if (File.Exists(filepath) && str.LastIndexOf('.') != -1)
                    {
                        before = str.Substring(0, str.LastIndexOf('.'));
                        end    = str.Substring(str.LastIndexOf('.'));
                    }
                    else
                    if (Directory.Exists(filepath))                            // 目录
                    {
                        before = str;
                    }
                    myarray.Add(before);

                    if (temp.Count == 0)
                    {
                        PinLv pinlv = new PinLv();
                        pinlv.data = end;
                        pinlv.cout = 0;
                        temp.Add(pinlv);
                    }
                    else
                    {
                        int j;
                        for (j = 0; j < temp.Count; j++)
                        {
                            PinLv p = (PinLv)temp[j];
                            if (str.CompareTo(p.data) == 0)
                            {
                                p.cout++;
                                temp[j] = p;
                                break;
                            }
                        }
                        if (j == temp.Count)
                        {
                            PinLv pinlv = new PinLv();
                            pinlv.data = str;
                            pinlv.cout = 0;
                            temp.Add(pinlv);
                        }
                    }
                    Node node = new Node();
                    node.id   = i;
                    node.data = end;
                    newarray.Add(node);
                }
                catch
                {
                }
            }
            if (newarray.Count == 0)
            {
                MessageBox.Show("请确定选中两个或两个以上有相同特征的文件!", "重命名", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(null);
            }
            string s = "";

            if (temp.Count == 0)
            {
                MessageBox.Show("不符合批处理条件!");
                return(null);
            }
            temp = arrayListSort(temp);
            PinLv pin = new PinLv();

            pin    = (PinLv)temp[0];
            s      = pin.data;
            common = new ArrayList();
            for (int i = 0; i < newarray.Count; i++)
            {
                Node node = (Node)newarray[i];
                if (s.CompareTo(node.data) == 0)
                {
                    common.Add(myarray[i] + s);
                }
            }
            return(common);
        }