Skip to content

Instantly share code, notes, and snippets.

@TheYkk

TheYkk/cssclear.py

Created Sep 8, 2018
Embed
What would you like to do?
Python clearing unused CSS
import os,ntpath,re
from fnmatch import fnmatch
folder_path = "C:/Users/TheYkk/Desktop/ko/Public/assets"
folder_path2 = "C:/Users/TheYkk/Desktop/ko/App/Views"
pattern = "*.css"
rev = ""
pattern2 = "*.php"
conten =0
#css dosyalarini bulmak icin
for path, subdirs, files in os.walk(folder_path):
for name in files:
if fnmatch(name, pattern):
rev = (os.path.join(path, name))
file = ntpath.basename((os.path.join(path, name)))
#php dosyalarini bulmak icin
for path2, subdirs2, files2 in os.walk(folder_path2) :
for name2 in files2:
if fnmatch(name2, pattern2):
file2 = (os.path.join(path2, name2))
#php dosyasi icinde arama
for line in open(r''+file2):
if line != '':
word = re.findall(file, line)
if len(word) > 0:
conten+=1
#print('sea ',file,' ', len(word),' ', conten )
#hicbir dosyada adi tam olarak gecmiyorsa siliyoruz
if conten > 0:
conten = 0
break
else:
print('silinecek',file,' ',conten)
os.remove(rev)
conten = 0
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment