Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //只判断处理文件夹
            foreach (string path in this.listBoxNameSet.Items)
            {
                if (Directory.Exists(path))
                {
                    string NewName = path.Substring(path.LastIndexOf("\\") + 1);
                    string NewPath = path.Remove(path.LastIndexOf("\\"));

                    List <string> file = CodeAll.ScanVideo(path, "*", SearchOption.AllDirectories);
                    if (file.Count != 1)
                    {
                        continue;
                    }

                    if (File.Exists(NewPath + "\\" + NewName + Path.GetExtension(file[0])))
                    {
                        continue;
                    }

                    try
                    {
                        File.Move(file[0], NewPath + "\\" + NewName + Path.GetExtension(file[0]));
                        Directory.Delete(path, true);
                    }
                    catch (Exception ex)
                    {
                        CodeAll.AddLog("移动失败", path, ex.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        //检查是否存在
        public static bool ExistData(string FilePath, string DataType, string MD5)
        {
            FileInfo fi = new FileInfo(FilePath);

            long     FileSize  = fi.Length;
            DateTime CreatTime = fi.CreationTime;

            if (MD5 == "")
            {
                MD5 = CodeAll.GetMD5(FilePath);
            }



            OleDbCommand command = new OleDbCommand();

            command.Connection = conn;
            OleDbDataReader dr = null;

            command.CommandText = "select [MD5] from " + DataType + " where [MD5] = '" + MD5 + "'";

            try
            {
                dr = command.ExecuteReader();
                bool Exist = dr.HasRows;
                return(Exist);
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("查询数据库失败", FilePath, ex.Message);

                return(true);
            }
        }
Esempio n. 3
0
        private void button11_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count == -1)
            {
                return;
            }

            foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
            {
                string path = item.Cells["FilePath"].Value.ToString();

                //删除文件
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    CodeAll.AddLog("文件删除失败", path, ex.Message);
                    continue;
                }

                this.dataGridView1.Rows.Remove(item);
            }
        }
Esempio n. 4
0
        public static void CreatTxtFile(string FilePath, string Name)
        {
            string DelPath = setting.DelTxtPath;

            if (Directory.Exists(DelPath) == false)
            {
                CodeAll.AddLog("文本数据库路径不存在", "", "");
                DelPath = setting.TempDelTxtPath;
                if (Directory.Exists(DelPath) == false)
                {
                    Directory.CreateDirectory(DelPath);
                }
            }

            if (File.Exists(FilePath) == false)
            {
                CodeAll.AddLog("NoFilePath", FilePath, "");
                return;
            }

            //获取文件大小


            long   lSize = new FileInfo(FilePath).Length;
            string size  = "";

            if (lSize >= 1073741824)
            {
                size = (lSize / 1024.00 / 1024.00 / 1024.00).ToString("F2") + "G";
            }
            else if (lSize >= 1048576)
            {
                size = (lSize / 1024.00 / 1024.00).ToString("F2") + "MB";
            }
            else if (lSize >= 1024)
            {
                size = (lSize / 1024.00).ToString("F2") + "KB";
            }
            else
            {
                size = lSize.ToString("F2") + "B";
            }

            //////////////////////////////////////////////

            string TxtPath = DelPath + Name + " " + size + ".txt";

            if (File.Exists(TxtPath) == false)
            {
                FileStream myFs = new FileStream(TxtPath, FileMode.Create);
                myFs.Close();
            }
            else
            {
                CodeAll.AddLog("Txt数据已存在", TxtPath, "");
            }
        }
Esempio n. 5
0
        //添加数据库
        //1.路径,名称,类型,是否删除
        //2.校验MD5数值,查询数据库是否存在
        //3.存在没标记删除(标记删除并记录),存在已标记删除(报错),不存在(添加)

        public static bool AddData(string FilePath, string Name, string DataType, string MD5, bool isDel)
        {
            if (DataType == "")
            {
                CodeAll.AddLog("数据库添加失败", "", "为选择类型");

                return(false);
            }

            //获取文件信息

            FileInfo fi = new FileInfo(FilePath);

            long     FileSize  = fi.Length;
            DateTime CreatTime = fi.CreationTime;

            if (MD5 == "")
            {
                MD5 = CodeAll.GetMD5(FilePath);
            }


            if (MD5 == "")
            {
                return(false);
            }

            //先查询是否存在 存在跳过 不存在添加数据

            if (ExistData(FilePath, DataType, MD5) == true)
            {
                CodeAll.AddLog("数据库添加失败", FilePath, "已存在");

                if (isDel)
                {
                    UpdateAccess("update " + DataType + " set [isDel] = " + isDel + " where [MD5] = '" + MD5 + "'");
                    CodeAll.AddLog("数据库标记删除", "", isDel.ToString());
                }
                else
                {
                    CodeAll.AddLog("跳过", "", "");
                }

                return(false);
            }
            else
            {
                return(UpdateAccess("insert into " + DataType + "([Name],[Size],[MD5],[UpdateTime],[CreatTime],[isDel]) values ('" + Name.Replace("'", "") + "','" + FileSize + "','" + MD5 + "','" + DateTime.Now + "','" + CreatTime + "'," + isDel + ")"));
            }
        }
Esempio n. 6
0
        public static DataTable GetAccess(string sql)
        {
            OleDbCommand command = new OleDbCommand();

            command.Connection = conn;

            OleDbDataReader dr = null;

            command.CommandText = sql;
            DataTable dt = new DataTable();


            try
            {
                dr = command.ExecuteReader();

                for (int i = 0; i < dr.FieldCount; i++)
                {
                    DataColumn dc = new DataColumn(dr.GetName(i), dr.GetFieldType(i));
                    dt.Columns.Add(dc);
                }

                while (dr.Read())
                {
                    DataRow ddr = dt.NewRow();
                    for (int i = 0; i < dr.FieldCount; i++)
                    {
                        ddr[i] = dr.GetValue(i).ToString();
                    }
                    dt.Rows.Add(ddr);
                }


                dr.Dispose();

                return(dt);
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("数据库操作失败", sql, ex.Message);
                return(null);
            }
        }
Esempio n. 7
0
        private void button14_Click(object sender, EventArgs e)
        {
            //是文件添加后缀修改,是文件夹直接修改

            List <string> Namelst = System.Text.RegularExpressions.Regex.Split(this.richTextBox2.Text.Trim(), "\n").ToList <string>();

            if (Namelst.Count != listBoxNameSet.Items.Count)
            {
                MessageBox.Show("文件数不一致");
                return;
            }

            for (int i = 0; i < listBoxNameSet.Items.Count; i++)
            {
                string OriPath = listBoxNameSet.Items[i].ToString();

                if (File.Exists(OriPath))
                {
                    string newPath = Path.GetDirectoryName(OriPath) + "\\" + Namelst[i].Trim() + Path.GetExtension(OriPath);
                    if (File.Exists(newPath))
                    {
                        continue;
                    }
                    File.Move(OriPath, newPath);
                }
                else if (Directory.Exists(OriPath))
                {
                    string newPath = Path.GetDirectoryName(OriPath) + "\\" + Namelst[i].Trim();
                    if (Directory.Exists(newPath))
                    {
                        continue;
                    }
                    Directory.Move(OriPath, newPath);
                }
                else
                {
                    CodeAll.AddLog("文件改名失败", OriPath, "文件不存在");
                }
            }

            MessageBox.Show("Done");
        }
Esempio n. 8
0
        public static bool UpdateAccess(string sql)
        {
            OleDbCommand command = new OleDbCommand();

            command.Connection = conn;

            command.CommandText = sql;

            try
            {
                command.ExecuteNonQuery();

                return(true);
            }

            catch (Exception ex)
            {
                CodeAll.AddLog("数据库操作失败", sql, ex.Message);

                return(false);
            }
        }
Esempio n. 9
0
        private void buttonDelSame_Click(object sender, EventArgs e)
        {
            //删除文件
            if (this.listBoxMD5.SelectedIndex == -1 || this.listBoxFile.SelectedIndex == -1)
            {
                return;
            }



            string path = this.listBoxFile.Items[this.listBoxFile.SelectedIndex].ToString();

            path = CodeClass.SameStrClear(path);


            if (System.IO.File.Exists(path) == false)
            {
                CodeAll.AddLog("文件删除失败", path, "文件不存在");
                return;
            }

            //删除文件
            try
            {
                File.Delete(path);
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("文件删除失败", path, ex.Message);
                return;
            }

            int selectIndex = this.listBoxFile.SelectedIndex;

            this.listBoxMD5.Items.RemoveAt(selectIndex);
            this.listBoxFile.Items.RemoveAt(selectIndex);

            CheckSameMD5List();
        }
Esempio n. 10
0
        //获取文件MD5校验码
        public static string GetMD5(string strFile)
        {
            try
            {
                int iFileSize = 30 * 1024 * 1024;

                //以文件的全路径对应的字符串和文件打开模式来初始化FileStream文件流实例
                FileStream SplitFileStream = new FileStream(strFile, FileMode.Open);
                //以FileStream文件流来初始化BinaryReader文件阅读器
                BinaryReader SplitFileReader = new BinaryReader(SplitFileStream);
                //每次分割读取的最大数据
                byte[] TempBytes = SplitFileReader.ReadBytes(iFileSize);

                MD5 md5 = MD5.Create();

                byte[] data2 = md5.ComputeHash(TempBytes);



                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < data2.Length; i++)
                {
                    sb.Append(data2[i].ToString("x2"));
                }

                SplitFileStream.Close();
                SplitFileReader.Close();
                return(sb.ToString());
            }
            catch (Exception ex)
            {
                CodeAll.AddLog("MD5验证失败", strFile, ex.Message);

                return("");
            }
        }
Esempio n. 11
0
        private void button4_Click(object sender, EventArgs e)
        {
            access.Open();
            if (MessageBox.Show("是否确认删除", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
            {
                return;
            }



            for (int i = 0; i < this.listBoxFile.Items.Count; i++)
            {
                string path = this.listBoxFile.Items[i].ToString();
                string Name = Path.GetFileNameWithoutExtension(path);


                if (GetDataType() == "")
                {
                    MessageBox.Show("未选择类型");

                    return;
                }

                string DataType = GetDataType();

                //除了G创建文本数据库
                if (DataType != "G")
                {
                    CodeClass.CreatTxtFile(path, Name);
                }


                //除了TXT模式创建MDB数据库
                if (DataType != "TXT")
                {
                    //listboxMD5数据数量不一致就重新计算MD5

                    string MD5 = "";


                    if (this.listBoxMD5.Items.Count == this.listBoxFile.Items.Count)
                    {
                        MD5 = this.listBoxMD5.Items[i].ToString();
                    }

                    if (access.AddData(path, Name, DataType, "", true) == false)
                    {
                        continue;
                    }
                }


                //删除文件
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    CodeAll.AddLog("文件删除失败", path, ex.Message);
                    continue;
                }
            }


            Clear();

            access.Close();
        }