コード例 #1
0
        public static List <DirectoryInfos> SearchTemplateFiles(string dir, string searchPattern)
        {
            var           list   = new List <DirectoryInfos>();
            DirectoryInfo info   = new DirectoryInfo(dir);
            string        str    = searchPattern;
            string        str2   = searchPattern.ToLower(CultureInfo.CurrentCulture);
            int           length = searchPattern.Length;

            if (length < 4)
            {
                str = "*" + str + "*.html";
            }
            else if ((str2.Substring(length - 4, 4) != ".html") || (str2.Substring(length - 3, 3) != ".htm"))
            {
                str = "*" + str + "*.html";
            }
            try
            {
                foreach (var info2 in info.GetFiles(str, SearchOption.AllDirectories))
                {
                    var model = new DirectoryInfos();
                    model.name          = info2.FullName.Remove(0, info.FullName.Length).Replace("/", "\"");
                    model.type          = 2;
                    model.size          = info2.Length;
                    model.content_type  = info2.Extension.Replace(".", string.Empty);
                    model.createTime    = info2.CreationTime;
                    model.lastWriteTime = info2.LastWriteTime;
                    list.Add(model);
                }
            }
            catch (ArgumentException)
            {
            }
            return(list);
        }
コード例 #2
0
        public static List <DirectoryInfos> SearchFiles(string dir, string searchPattern)
        {
            var           list = new List <DirectoryInfos>();
            DirectoryInfo info = new DirectoryInfo(dir);

            foreach (var info2 in info.GetFiles(searchPattern, SearchOption.AllDirectories))
            {
                var model = new DirectoryInfos();
                model.name          = info2.FullName.Remove(0, info.FullName.Length);
                model.type          = 2;
                model.size          = info2.Length;
                model.content_type  = info2.Extension.Replace(".", string.Empty);
                model.createTime    = info2.CreationTime;
                model.lastWriteTime = info2.LastWriteTime;
                list.Add(model);
            }
            return(list);
        }
コード例 #3
0
        public static List <DirectoryInfos> GetDirectoryInfos(string dir, FsoMethod method)
        {
            var list = new List <DirectoryInfos>();

            dir = FileHelper.MapPath(dir);
            if (method != FsoMethod.File)
            {
                for (int i = 0; i < Directory.GetDirectories(dir).Length; i++)
                {
                    var           model    = new DirectoryInfos();
                    DirectoryInfo d        = new DirectoryInfo(Directory.GetDirectories(dir)[i]);
                    Int64[]       numArray = DirInfo(d);
                    model.name          = d.Name;
                    model.type          = 1;
                    model.size          = numArray[0];
                    model.content_type  = string.Empty;
                    model.createTime    = d.CreationTime;
                    model.lastWriteTime = d.LastWriteTime;
                    model.path          = d.Name;
                    model.Id            = i + 1;
                    list.Add(model);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (int j = 0; j < Directory.GetFiles(dir).Length; j++)
                {
                    var model = new DirectoryInfos();
                    var info2 = new System.IO.FileInfo(Directory.GetFiles(dir)[j]);
                    model.name          = info2.Name;
                    model.type          = 2;
                    model.size          = info2.Length;
                    model.content_type  = info2.Extension.Replace(".", string.Empty);
                    model.createTime    = info2.CreationTime;
                    model.lastWriteTime = info2.LastWriteTime;
                    model.path          = info2.Name;
                    model.Id            = j + 1;
                    list.Add(model);
                }
            }
            return(list);
        }
コード例 #4
0
        public static List <DirectoryInfos> SearchFileContent(string dir, string searchPattern, string searchKeyword)
        {
            var           list = new List <DirectoryInfos>();
            DirectoryInfo info = new DirectoryInfo(dir);

            foreach (var info2 in info.GetFiles(searchPattern, SearchOption.AllDirectories))
            {
                var          model  = new DirectoryInfos();
                StreamReader reader = info2.OpenText();
                string       str    = reader.ReadToEnd();
                reader.Dispose();
                if (str.Contains(searchKeyword))
                {
                    model.name          = info2.FullName.Remove(0, info.FullName.Length);
                    model.type          = 2;
                    model.size          = info2.Length;
                    model.content_type  = info2.Extension.Replace(".", string.Empty);
                    model.createTime    = info2.CreationTime;
                    model.lastWriteTime = info2.LastWriteTime;
                    list.Add(model);
                }
            }
            return(list);
        }