Пример #1
0
        public FileFilterOptions Clone()
        {
            FileFilterOptions clone = new FileFilterOptions();

            clone.bIncludeOnly = bIncludeOnly;
            clone.IncludeOnly  = (string)IncludeOnly.Clone();

            clone.AlwaysExclude = (string)AlwaysExclude.Clone();

            return(clone);
        }
Пример #2
0
        public bool CheckIfFileOK(String path)
        {
            string name      = System.IO.Path.GetFileName(path);
            string orgFilter = IncludeOnly.Replace(" ,", ",").Replace(", ", ","); // Remove Spaces

            string[] arrOrgFilter = orgFilter.Split(',');

            // ________IncludeOnly___________

            bool bResult_IncludeOnly = false;

            if (bIncludeOnly == true)
            {
                string regexFilter = "^"; // start

                bool firstloop = true;
                foreach (string strFilter in arrOrgFilter)
                {
                    if (!firstloop)
                    {
                        regexFilter += "|";
                    }
                    firstloop = false;

                    regexFilter += "(?i)";                                                                                          // Case insensitive

                    regexFilter += System.Text.RegularExpressions.Regex.Escape(strFilter).Replace(@"\*", ".*").Replace(@"\?", "."); // need to escape first, so dots are read as dots etc.
                }
                regexFilter += "$";                                                                                                 // end

                //System.Text.RegularExpressions.Regex.Escape(regexFilter);

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(regexFilter);

                bResult_IncludeOnly = regex.IsMatch(name);
            }
            else
            {
                bResult_IncludeOnly = true;
            }



            // _______always Exclude_______


            bool bResult_AlwaysExclude = true;

            orgFilter    = AlwaysExclude.Replace(" ,", ",").Replace(", ", ","); // Remove Spaces
            arrOrgFilter = orgFilter.Split(',');


            {
                string regexFilter = "^"; // start

                bool firstloop = true;
                foreach (string strFilter in arrOrgFilter)
                {
                    if (!firstloop)
                    {
                        regexFilter += "|";
                    }
                    firstloop = false;

                    regexFilter += "(?i)";                                                                                          // Case insensitive

                    regexFilter += System.Text.RegularExpressions.Regex.Escape(strFilter).Replace(@"\*", ".*").Replace(@"\?", "."); // need to escape first, so dots are read as dots etc.
                }
                regexFilter += "$";                                                                                                 // end

                //System.Text.RegularExpressions.Regex.Escape(regexFilter);

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(regexFilter);

                bResult_AlwaysExclude = regex.IsMatch(name);
            }

            /*
             * if (bResult_AlwaysExclude == true)
             * {
             *  int breakpoint = 5;
             * }
             */

            return(!bResult_AlwaysExclude && bResult_IncludeOnly);
        }