import os from PyQt5.QtCore import QDir path = '/path/to/directory' for root, dirs, files in os.walk(path): for file in files: print(os.path.join(root, file))
from PyQt5.QtCore import QDir dir = QDir('/path/to/directory') for file in dir.entryList(): print(file)
from PyQt5.QtCore import QDir dir = QDir('/path/to/directory') file = 'example.txt' if dir.exists(file): print('File {} exists'.format(file)) else: print('File {} does not exist'.format(file))Overall, these examples demonstrate PyQt5's use of the QtCore module and QDir class to work with directories and their contents.