In [1]:
import os

In [2]:
os.makedirs('temp/', exist_ok=True)

In [3]:
with open('temp/file.txt', 'w') as f:
    f.write('')

In [4]:
print(os.listdir('temp'))


['file.txt']

In [5]:
os.remove('temp/file.txt')

In [6]:
print(os.listdir('temp'))


[]

In [7]:
# os.remove('temp/')
# PermissionError: [Errno 1] Operation not permitted: 'temp/'