I want to generate a wildcard string from a pair of file names. Kind of an inverse-glob. Example:
file1 = 'some foo file.txt'
file2 = 'some bar file.txt'
assert 'some * file.txt' == inverse_glob(file1, file2)
Use difflib perhaps? Has this been solved already?
Application is a large set of data files with similar names. I want to compare each pair of file names and then present a comparison of pairs of files with "similar" names. I figure if I can do a reverse-glob on each pair, then those pairs with "good" wildcards (e.g. not lots*of*stars*.txt
nor *
) are good candidates for comparison. So I might take the output of this putative inverse_glob()
and reject wildcards that have more than one *
or for which glob()
doesn't produce exactly two files.