Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / C++

CEnum - File Enumeration and File Globbing Class

Rate me:
Please Sign up or sign in to vote.
4.45/5 (5 votes)
6 Dec 2008CPOL12 min read 52.9K   1.2K   48  
CEnum is used for enumeration of files and directories using wildcard matching (globbing)
# test zero or more characters

"*"                 ""                                      true
"*"                 " "                                     true
"*"                 "a"                                     true
"*"                 "a "                                    true
"*"                 ".a"                                    true
"*"                 "*"                                     true
"*"                 "?"                                     true
"*"                 "abcd"                              true
"*"                 ";+*'?(/&%$#!_"             true

# test exactly one character

"?"                 ""                                      false
"?"                 " "                                     true
"?"                 "a"                                     true
"?"                 "."                                     true
"?"                 "?"                                     true
"?"                 "*"                                     true
"?"                 "!"                                     true
"?"                 "ab"                                    false

# at least one character, any character

"*?"                ""                                      false
"*?"                " "                                     true
"*?"                "a"                                     true
"*?"                "ab"                                    true
"*?"                "a.b"                                   true

# at least one character, last one is 'b'

"*b"                "b"                                     true
"*b"                "ab"                                    true
"*b"                "aab"                                   true
"*b"                "abc"                                   false

# exactly two characters, second one is 'c'

"?c"                "c"                                     false
"?c"                "bc"                                    true
"?c"                "abc"                                   false
"?c"                "bcd"                                   false

# at least two characters, last one is 'c'

"*?c"               "c"                                     false
"*?c"               "bc"                                    true
"*?c"               "abc"                                   true
"*?c"               "abcd"                                  false

# same test, just with inverted wildcard chars

"?*c"               "c"                                     false
"?*c"               "bc"                                    true
"?*c"               "abc"                                   true
"?*c"               "abcd"                                  false

# file name test, find strings with a dot in it

"*.*"               ""                                      false
"*.*"               " "                                     false
"*.*"               "."                                     true
"*.*"               ".ab"                                   true
"*.*"               "a.b"                                   true
"*.*"               "ab."                                   true
"*.*"               ".a.b"                                  true
"*.*"               "a..b"                                  true
"*.*"               "..."                                   true

# test reoccurring substrings

"ab*cd*ef*gh"       "ab c1 cd e1 ef g1 gh"                  true
"ab*cd*ef*gh"       ""ab*cd*ef*gh"                          true
"ab*cd*ef*gh"       "abcdefgh"                              true

# misc, some of these might already been tested previously

"*t?st?n*this*t*"    "testin this sh*t"                     true

"????"              "abcd"                                  true
"????"              "abcde"                                 false
"*b"                "abc"                                   false
"a*???bc"            "axxxxbcxxxxbc"                         true
"a*???bc"            "axxxxbdxxxxbc"                         true
"a*???bc"            "axxxxbcaxxxxbc"                         true
"a*bc"               "axxxbcxxxbc"                           true

"*?"                "ab"                                    true
"*?c"                "abc"                                    true

"*b"                "abc"                                   false

"*???"				"ab"									false

"*?"                "ab"                                    true
"*?"                "a"                                    true
"*?"                ""                                    false
"*?a"                "aa"                                    true
"*?a"                "ba"                                    true
"*?a"                "a"                                    false
"*?"                ""                                    false

"a*bc"             "aabdbc"                                 true
"a*bcdef"          "aabcderdbcbcdef"                        true

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Croatia Croatia
Nothing to brag about.
Just another engineer who works as a software developer last couple of years.

Comments and Discussions