Exemplo n.º 1
0
        public CaseModel Func_DirectoryFileInfo()
        {
            return(new CaseModel()
            {
                NameSign = @"文件夹文件遍历",
                ExeEvent = () => {
                    return true;

                    string abspath = @"D:\auto\circleoffriends";

                    DirectoryInfo dir = new DirectoryInfo(abspath);

                    // 最新的三条
                    DirectoryInfo[] sondir = PathHelp.UpToDateDirectorys(dir, 2, 3);

                    foreach (DirectoryInfo info in sondir)
                    {
                        Console.WriteLine("Directory name: {0}, create time: {1}", info.Name, info.CreationTime);

                        FileInfo[] fis = PathHelp.PatternFileInfo(info, @".*\.(jpg|png|gif)");
                        foreach (FileInfo fi in fis)
                        {
                            Console.WriteLine("  File name: {0}, create time: {1}", fi.Name, fi.CreationTime);
                        }

                        Console.WriteLine(string.Empty);
                    }

                    return true;
                },
            });
        }
Exemplo n.º 2
0
            public bool Method()
            {
                const string oldpath = @"D:\ZRQDownloads\imgs";

                DirectoryInfo[] sondirs = PathHelp.AllSonDirectorys(new DirectoryInfo(oldpath));
                foreach (DirectoryInfo dirinfo in sondirs)
                {
                    FileInfo[] fis = PathHelp.PatternFileInfo(dirinfo, @".*\.(jpg|png|gif)");
                    foreach (FileInfo file in fis)
                    {
                        Calc(dirinfo, file);
                    }
                }
                return(false);
            }
Exemplo n.º 3
0
        public CaseModel Func_Compression()
        {
            return(new CaseModel()
            {
                NameSign = @"压缩计算",
                ExeEvent = () => {
                    const string oldpath = @"D:\ZRQDownloads\imgs";
                    if (!Directory.Exists(oldpath))
                    {
                        Console.WriteLine("停止执行, 路径不存在: {0}", oldpath);
                        return true;
                    }

                    ImageHandler handler = new ImageHandler();
                    const int maxwidth = 1200;
                    const int maxheight = 1200;
                    handler.SetMaxSize(maxwidth, maxheight);
                    const long maxbytelength = 2 * 1024 * 1024;
                    handler.SetMaxByteLength(maxbytelength);

                    DirectoryInfo[] sondirs = PathHelp.AllSonDirectorys(new DirectoryInfo(oldpath));
                    foreach (DirectoryInfo dirinfo in sondirs)
                    {
                        FileInfo[] fis = PathHelp.PatternFileInfo(dirinfo, @".*\.(jpg|png|gif)");
                        foreach (FileInfo file in fis)
                        {
                            byte[] imgvalues = handler.Calc(file);
                            if (CheckData.IsSizeEmpty(imgvalues))
                            {
                                Console.WriteLine("压缩图片失败, 结果为空!");
                                Console.WriteLine("FileInfo.FullName: {0}", file.FullName);
                                return false;
                            }
                            string newdirpath = file.DirectoryName.Replace("imgs", "imgs_c");
                            string newfilepath = PathHelp.CreateUseFilePath(newdirpath, file.Name);
                            handler.SaveImg(imgvalues, newfilepath);
                        }
                    }
                    return true;
                },
            });
        }