Extracting Specific Files Within Directory - Windows
I am running a loop which needs to access circa 200 files in the directory. In the folder - the format of the files range as follows: Excel_YYYYMMDD.txt Excel_YYYYMMDD_V2.txt Ex
Solution 1:
Here is a cheap way to do it (and by cheap I mean probably not the best/cleanest method):
importglobl= glob.glob("Excel_[0-9]*.txt")
This will get you:
>>> print(l)
['Excel_19900717_orig.txt', 'Excel_19900717_V2.txt', 'Excel_19900717.txt']
Now filter it yourself:
nl = [x for x in l if "_orig" not in x and "_V2" not in x]
This will give you:
>>> print(nl)
['Excel_19900717.txt']
The reason for manually filtering through our glob is because the glob library does not support regex.
Solution 2:
Use ^Excel_[0-9]{8}\.txt
as the file matching regex.
Post a Comment for "Extracting Specific Files Within Directory - Windows"