Created
September 8, 2018 11:12
-
-
Save TheYkk/7ecb7dd8b162bb190bd597e6207c7694 to your computer and use it in GitHub Desktop.
Python clearing unused CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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