Example #1
0
        /// <summary>
        /// 批量生成目录下所有图片缩略图
        /// </summary>
        /// <param name="spath">全文件路径</param>
        /// <param name="isChild">子目录是否生成</param>
        public static void CreateSImg(string spath, bool isChild)
        {
            DirectoryInfo[] ChildDirectory;                            //子目录集
            FileInfo[]      NewFileInfo;                               //当前所有文件
            string          path            = spath;
            DirectoryInfo   FatherDirectory = new DirectoryInfo(path); //当前目录

            ChildDirectory = FatherDirectory.GetDirectories("*.*");    //得到子目录集

            //根目录文件
            NewFileInfo = FatherDirectory.GetFiles();
            foreach (FileInfo DirFile in NewFileInfo)//获取此级目录下的所有文件
            {
                if (!DirFile.FullName.ToLower().EndsWith(".jpg") && !DirFile.FullName.ToLower().EndsWith(".png") && !DirFile.FullName.ToLower().EndsWith(".gif") && !DirFile.FullName.ToLower().EndsWith(".ico") && !DirFile.FullName.ToLower().EndsWith(".bmp"))
                {
                    //不是 图片 返回。
                    continue;
                }
                string sfile = ""; //小
                string mfile = ""; //中

                sfile = DirFile.FullName.ToLower().Replace(EKFile.GetMapPath("/" + MS_ConfigBLL.UploadPath).ToLower(), EKFile.GetMapPath("/") + "/" + MS_ConfigBLL.UploadPath_X + "/" + MS_ConfigBLL.UploadPath);
                mfile = DirFile.FullName.ToLower().Replace(EKFile.GetMapPath("/" + MS_ConfigBLL.UploadPath).ToLower(), EKFile.GetMapPath("/") + "/" + MS_ConfigBLL.UploadPath_Z + "/" + MS_ConfigBLL.UploadPath);

                EKFile.CreateDirectory(mfile.Remove(mfile.LastIndexOf("\\")));
                EKFile.CreateDirectory(sfile.Remove(sfile.LastIndexOf("\\")));

                try
                {
                    if (DirFile.FullName.ToLower().EndsWith(".gif") || DirFile.FullName.ToLower().EndsWith(".ico"))
                    {
                        //gif会动,不处理。ico 不处理
                        EKFile.CopyFile(DirFile.FullName, sfile);
                        EKFile.CopyFile(DirFile.FullName, mfile);
                    }
                    else
                    {
                        if (!File.Exists(sfile))
                        {
                            EKFileUpload.ImageUpLoad(DirFile.FullName, sfile, 150, 150);
                        }
                        if (!File.Exists(mfile))
                        {
                            EKFileUpload.ImageUpLoad(DirFile.FullName, mfile, 500, 500);
                        }
                    }
                }
                catch
                {
                    //m_new.NewsTitle = DirFile.FullName + "-----" + zfile;
                    //b_new.Add(m_new);
                    continue;
                }
            }

            //子目录是否生成
            if (isChild)
            {
                foreach (DirectoryInfo dirInfo in ChildDirectory)//目录
                {
                    if (dirInfo.Attributes.ToString().Contains("Hidden"))
                    {
                        continue;
                    }
                    CreateSImg(dirInfo.FullName, isChild);
                }
            }
        }