X
X

Select Your Currency

Türk Lirası $ US Dollar
X
X

Select Your Currency

Türk Lirası $ US Dollar
Yıllık Satın Alımlarda %15 İndirim: Şimdi Tasarruf Edin! Detaylı Bilgi İçin Tıklayın!

Knowledge Base

HomepageKnowledge BaseGeneralCleaning garbage files from website...

Cleaning garbage files from website using Python

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))

Can't find the information you're looking for?

You have examined the knowledge base in detail, but if you cannot find the information you need,

Create a Support Ticket
Did you find it useful?
(85 times viewed. / 0 people found helpful.)