You can use the example below to clean up unused files on your website using Python.
import os
folder_path = '/home/teknosos/PycharmProjects/kuaforgold/static/panel/img/profilfotolar/'
extensions = ['.jpg', '.png']
used_files = ['0.jpg', '1.jpg']
## Return all files in folder and subfolders
for file_folder, folders, files in os.walk(folder_path):
## Return found files
for file in files:
### If the extension of the file is in the desired extension list
if file.endswith(tuple(extensions)):
#### If the file is not in the used file list
if not file in used_files:
deleted_file = '{}{}'.format(file_folder, file)
##### Delete file
os.remove(deleted_file)
print('Deleted: {}'.format(deleted_file))
You have examined the knowledge base in detail, but if you cannot find the information you need,
Create a Support Ticket