In [1]:
import util_make_files
util_make_files.glob_example_detail()
In [2]:
import glob
import re
import os
In [3]:
l = glob.glob('temp/*.txt')
In [4]:
print(l)
In [5]:
print(type(l))
In [6]:
print(glob.glob('temp/*'))
In [7]:
print(glob.glob('temp/*.txt'))
In [8]:
print(glob.glob('temp/dir/*/*.text'))
In [9]:
print(glob.glob('temp/???.*'))
In [10]:
print(glob.glob('temp/[0-9].*'))
In [11]:
print(glob.glob('temp/[0-9][0-9].*'))
In [12]:
print(glob.glob('temp/[a-z][a-z][a-z].*'))
In [13]:
print(glob.glob('temp/[[]*'))
In [14]:
print(glob.glob('temp/dir/*/*.text'))
In [15]:
print(glob.glob('temp/**/*.text', recursive=True))
In [16]:
print(glob.glob('temp/**', recursive=True))
In [17]:
print([p for p in glob.glob('temp/**', recursive=True)
if os.path.isfile(p)])
In [18]:
print([os.path.basename(p) for p in glob.glob('temp/**', recursive=True)
if os.path.isfile(p)])
In [19]:
print(glob.glob('temp/**/', recursive=True))
In [20]:
print(os.path.join('temp', '**' + os.sep))
In [21]:
print(glob.glob(os.path.join('temp', '**' + os.sep), recursive=True))
In [22]:
print([os.path.basename(p.rstrip(os.sep)) for p
in glob.glob(os.path.join('temp', '**' + os.sep), recursive=True)])
In [23]:
print([p for p in glob.glob('temp/**', recursive=True)
if re.search('\d+\.txt', p)])
In [24]:
print([p for p in glob.glob('temp/**', recursive=True)
if re.search('/\D{3}\.(txt|text)', p)])
In [25]:
print(type(glob.iglob('temp/*.txt')))
In [26]:
for p in glob.iglob('temp/*.txt'):
print(p)
In [27]:
import shutil
shutil.rmtree('temp')
os.mkdir('temp')