I have a folder with subfolders that are all in the pattern YYYYMMDDHHMMSS (timestamp).
I want to use glob to only select the folders that match that pattern.
I have a folder with subfolders that are all in the pattern YYYYMMDDHHMMSS (timestamp).
I want to use glob to only select the folders that match that pattern.
Since
glob
doesn't support regular expressions, you'll have to brute-force creating the match string. One way is to take advantage of the fact that character ranges in[]
are expanded:I took advantage of the fact that in Python, multiplying a string with an integer n results in that string being repeated n times.
Of course, you might want to go ahead and put in a check to verify that the given path is actually a directory: