In [1]:
import util_make_files
util_make_files.glob_example_detail()
In [2]:
import pathlib
import glob
import re
import pprint
In [3]:
p_temp = pathlib.Path('temp')
In [4]:
print(p_temp)
In [5]:
print(type(p_temp))
In [6]:
print(type(p_temp.iterdir()))
In [7]:
pprint.pprint(list(p_temp.iterdir()))
In [8]:
# print(list(pathlib.Path('temp/1.txt').iterdir()))
# NotADirectoryError: [Errno 20] Not a directory: 'temp/1.txt'
In [9]:
p_temp = pathlib.Path('temp')
In [10]:
print(type(p_temp.glob('**/*.txt')))
In [11]:
pprint.pprint(list(p_temp.glob('**/*.txt')))
In [12]:
pprint.pprint(list(p_temp.glob('*')))
In [13]:
pprint.pprint(list(p_temp.glob('dir/*/*.text')))
In [14]:
pprint.pprint(list(p_temp.glob('???.*')))
In [15]:
pprint.pprint(list(p_temp.glob('[a-z][a-z][a-z].*')))
In [16]:
pprint.pprint(glob.glob('temp/**', recursive=True))
In [17]:
pprint.pprint(list(p_temp.glob('**')))
In [18]:
pprint.pprint(list(p_temp.glob('**/*')))
In [19]:
pprint.pprint([p for p in p_temp.glob('**/*')
if re.search('\d+\.txt', str(p))])
In [20]:
pprint.pprint([p for p in p_temp.glob('**/*')
if re.search('/\D{3}\.(txt|text)', str(p))])
In [21]:
pprint.pprint([p.resolve() for p in p_temp.iterdir()])
In [22]:
pprint.pprint([str(p) for p in p_temp.iterdir()])
In [23]:
pprint.pprint([p for p in p_temp.iterdir() if p.is_file()])
In [24]:
pprint.pprint([p for p in p_temp.iterdir() if p.is_dir()])
In [25]:
pprint.pprint([p.name for p in p_temp.iterdir() if p.is_file()])
In [26]:
pprint.pprint([p for p in p_temp.glob('**/*')
if re.search('\d+\.txt', str(p))])
In [27]:
for p in p_temp.glob('**/*'):
if re.search('\d+\.txt', str(p)) and p.is_file():
p.unlink()
In [28]:
pprint.pprint([p for p in p_temp.glob('**/*')
if re.search('\d+\.txt', str(p))])
In [29]:
[p.unlink() for p in p_temp.glob('**/*') if re.search('\d+\.txt', str(p)) and p.is_file()]
Out[29]:
In [30]:
import shutil
shutil.rmtree('temp')