Beispiel #1
0
        public static void GetFilebyExt_BFS(Queue <string> queue_result, string root, string[] ext)//tìm kiếm theo chiều rộng
        {
            var path = root;

            string[] next = null;
            try
            {
                next = Directory.GetDirectories(path);              //lấy ra toàn bộ folder con
            }
            catch { }
            try
            {
                next = Directory.GetFiles(path);                    //lấy ra toàn bộ file trong folder đấy
            }
            catch { }
            if (next != null)
            {
                foreach (string item in next)                       //kiếm tra trong các file tên có chứa đuôi cần tìm
                {
                    if (XPath.IsEqualExt(item, ext))
                    {
                        queue_result.Enqueue(item);
                    }
                }
            }
        }
        //Chuyển file doc sang rtf để đọc
        //path là lưu đường dấn
        private static void DocToRtf(string filePath)
        {
            //Creating the instance of Word Application
            if (chuyendoiRTF != null)
            {
                chuyendoiRTF(null, EventArgs.Empty);
            }
            Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
            object Unknown = Type.Missing;

            if (XPath.IsEqualExt(filePath, new string[] { ".doc", ".docx" }))
            {
                try
                {
                    //lấy địa chỉ file word
                    object Source = filePath;
                    //địa chỉ file rtf tạo ra tạm
                    object Target = XPath.pathfile_rft;
                    //nếu file tồn tại thì xóa đi
                    if (File.Exists(Target.ToString()))
                    {
                        File.Delete(Target.ToString());
                    }
                    // Use for the parameter whose type are not known or
                    // say Missing
                    // Source document open here
                    // Additional Parameters are not known so that are
                    // set as a missing type
                    newApp.Documents.Open(ref Source, ref Unknown,
                                          ref Unknown, ref Unknown, ref Unknown,
                                          ref Unknown, ref Unknown, ref Unknown,
                                          ref Unknown, ref Unknown, ref Unknown,
                                          ref Unknown, ref Unknown, ref Unknown, ref Unknown);
                    // Specifying the format in which you want the output file
                    object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
                    //Changing the format of the document
                    newApp.ActiveDocument.SaveAs(ref Target, ref format,
                                                 ref Unknown, ref Unknown, ref Unknown,
                                                 ref Unknown, ref Unknown, ref Unknown,
                                                 ref Unknown, ref Unknown, ref Unknown,
                                                 ref Unknown, ref Unknown, ref Unknown,
                                                 ref Unknown, ref Unknown);
                    // for closing the application
                    newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
                }
                catch (Exception)
                {
                }
                finally
                {
                    // for closing the application
                    newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
                }
            }
            else
            {
                return;
            }
        }
        //Kiểm tra xem path(đường dẫn) có thỏa mãn với bộ lọc có sẵn không
        public bool IsSatisfy(string path)
        {
            bool check = true;

            if (this.ext != null)
            {
                if (XPath.IsEqualExt(path, this.ext))
                {
                    check = true;
                }
                else
                {
                    return(false);
                }
            }
            if (this.createTimeFrom != null || this.lenghtMax != 0)
            {
                System.IO.FileInfo temp = new System.IO.FileInfo(path);
                if (this.createTimeFrom != null)
                {
                    if (temp.CreationTime <= this.createTimeTo && temp.CreationTime >= this.createTimeFrom)
                    {
                        check = true;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (!(System.IO.File.GetAttributes(path).HasFlag(System.IO.FileAttributes.Directory)))
                {
                    if (this.lenghtMax != 0)
                    {
                        if (temp.Length <= this.lenghtMax && temp.Length >= this.lenghtMin)
                        {
                            check = true;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            return(check);
        }
Beispiel #4
0
        public static void GetAllFilebyExt_BFS(Queue <string> queue_result, string root, string[] ext)//tìm kiếm theo chiều rộng
        {
            //load danh sách theo chiêu rộng

            Queue <string> pending = new Queue <string>();

            pending.Enqueue(root);
            while (pending.Count != 0)
            {
                var      path = pending.Dequeue();
                string[] next = null;
                try
                {
                    next = Directory.GetDirectories(path);              //lấy ra toàn bộ folder con
                    foreach (var subdir in next)
                    {
                        pending.Enqueue(subdir);                           //cho vào trong stack
                    }
                }
                catch { }
                try
                {
                    next = Directory.GetFiles(path);                    //lấy ra toàn bộ file trong folder đấy
                }
                catch { }
                if (next != null)
                {
                    foreach (string item in next)                       //kiếm tra trong các file tên có chứa đuôi cần tìm
                    {
                        if (XPath.IsEqualExt(item, ext))
                        {
                            queue_result.Enqueue(item);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        //Trả về danh sách path chứa đuôi thỏa mãn các từ trong ext ở trong folder có đường dẫn là root
        public static IEnumerable <string> GetFilebyExt_DFS(string root, string[] ext)//tìm kiếm theo chiều sâu
        {
            //load danh sách theo chiêu sâu
            Stack <string> pending = new Stack <string>();

            pending.Push(root);
            while (pending.Count != 0)
            {
                var      path = pending.Pop();
                string[] next = null;
                try
                {
                    next = Directory.GetDirectories(path);              //lấy ra toàn bộ folder con
                    foreach (var subdir in next)
                    {
                        pending.Push(subdir);                           //cho vào trong stack
                    }
                }
                catch { }
                try
                {
                    next = Directory.GetFiles(path);                    //lấy ra toàn bộ file trong folder đấy
                }
                catch { }
                if (next != null)
                {
                    foreach (string item in next)                       //kiếm tra trong các file tên có chứa đuôi cần tìm
                    {
                        if (XPath.IsEqualExt(item, ext))
                        {
                            yield return(item);
                        }
                    }
                }
            }
        }