I need to compare file system wildcard expressions to see whether their results would overlap, by only examining/comparing the expressions.
For sake of example, we are building a utility that would sort files from one (or more locations) into a separate folders based on file system wildcard expressions. For example: *.txt goes into folder a, *.doc goes into folder b, and so on. The wildcard characters we would support would be * and ?
I want to be able to determine from just analyzing the wildcard expressions, whether they would conflict/overlap.
For example, if I have the following expressions:
*.x.y *.y
They would conflict (overlap) because the second expression *.y would include *.x.y results. (ex. A.x.y would match both expressions)
I am approaching this by building a tree structure using the using all of the expressions, figuring that the very act of building a tree will fail if the expressions conflict.
For example: *.x a.b a.c b.d might create a tree like +-*-.-x | start +--+ | +-b | | +-a-.-+-c | | +-b-.-d
If I try to add the pattern b.x, the tree would be successful following the *.x path, and thereby say that the pattern already exists.
Am I heading in the correct direction? Or is there an known algorithm for attacking this?
See Question&Answers more detail:os