Example #1
0
        //加入数据
        public void AddFolderData()
        {
            Console.WriteLine("请输入要读入的目录:");
            string input = Console.ReadLine();

            if (!Directory.Exists(input))
            {
                Console.WriteLine("目录不存在!点击回车继续!");
                return;
            }
            int num = 0;

            //如果设定遍历目录
            if (OverAllData.if_traversal)
            {
                List <FileInfo> all_file = new List <FileInfo>();
                GetAllFileListFromFolder(input, all_file);
                foreach (FileInfo fi in all_file)
                {
                    Console.WriteLine("写入数据:" + fi.Name);
                    sqlcom.InsertData(fi.Name, getHash.GetSHA256Hash(fi));
                    num++;
                }
            }
            //不遍历目录
            else
            {
                DirectoryInfo di = new DirectoryInfo(input);
                foreach (FileInfo fi in di.GetFiles())
                {
                    Console.WriteLine("写入数据:" + fi.Name);
                    sqlcom.InsertData(fi.Name, getHash.GetSHA256Hash(fi));
                    num++;
                }
            }
            Console.WriteLine($"已写入{num}条数据!点击回车继续!");
        }