1+ # -*- coding: utf-8 -*-
2+ # Created on : 2025-08-09
3+ # @author : mefamex
4+ # FOR : mefamex.com website depth file
5+
6+ print (
7+ "\n " ,
8+ "#" * 30 ,
9+ "\n "
10+ "**Dizin Yapısı Görselleştirme Aracı**\n \n "
11+ "Bu Python uygulaması, belirtilen bir dizin yolundaki tüm dosya ve dizinleri detaylı bir şekilde analiz eder.\n "
12+ "Dosya boyutları, oluşturulma tarihleri, dizin hiyerarşisi gibi bilgileri görsel ve metinsel olarak sunar.\n "
13+ "Sistem yöneticileri, geliştiriciler ve veri bilimcileri için disk kullanımını optimize etmek, dosya yönetimini\n "
14+ "kolaylaştırmak ve veri analizi yapmak için ideal bir araçtır.\n \n "
15+ "**Ana Özellikler:**\n "
16+ "* **Rekürsif Dizin Gezimi:** Belirtilen dizin ve tüm alt dizinlerini inceler.\n "
17+ "* **Detaylı Bilgi Toplama:** Dosya boyutu, oluşturulma tarihi, dizin derinliği gibi bilgileri hesaplar.\n "
18+ "* **Formatlı Çıkış:** Tablo şeklinde okunaklı bir terminal çıktısı sunar.\n "
19+ "* **Metin Dosyasına Kaydetme:** Sonuçları bir metin dosyasına kaydeder.\n "
20+ "* **Özelleştirilebilir:** Çıkış formatı, analiz derinliği gibi ayarlar yapılabilir.\n \n "
21+ "**Kullanılan Modüller:**\n "
22+ "* os modülü\n "
23+ "* datetime modülü\n \n "
24+ "**Uyarılar:**\n "
25+ "* Çok büyük dizinlerde performans düşüşü yaşanabilir.\n "
26+ "* Dosya erişim hakları konusunda dikkatli olunmalıdır.\n \n "
27+ + "#" * 82 + "\n \n "
28+ )
29+
30+ import os ,time , datetime
31+
32+ text = '# Created for : mefamex.com files\n # Created on : ' + datetime .datetime .now ().isoformat (timespec = 'seconds' ) + 'Z\n '
33+
34+
35+ def count_characters_in_file (file_path ):
36+ try :
37+ with open (file_path , 'r' , encoding = 'utf-8' ) as file :
38+ content = file .read ()
39+ return len (content )
40+ except Exception as e :
41+ print (f"Hata: { file_path } dosyası okunamadı - { str (e )} " )
42+ return 0
43+
44+
45+
46+ def create_table (results , grand_total_char , grand_total_files ):
47+ """Tablo formatında sonuçları oluşturur"""
48+
49+ # Verileri hazırla (char sayısına göre sıralanmış)
50+ table_data , sorted_exts = [], sorted (results .keys (), key = lambda ext : results [ext ]['total_chars' ], reverse = True )
51+
52+ for ext in sorted_exts :
53+ file_count , char_count = len (results [ext ]['files' ]), results [ext ]['total_chars' ]
54+ table_data .append ({ 'type' : ext [1 :].upper (), 'char' : f"{ char_count :,} " if char_count > 0 else "---" , 'file' : str (file_count ) if file_count > 0 else "---" })
55+
56+ # Sütun genişliklerini hesapla
57+ type_width = max (len ("TYPE" ), max (len (row ['type' ]) for row in table_data )) + 2
58+ char_width = max (len ("CHAR" ), max (len (row ['char' ]) for row in table_data )) + 2
59+ file_width = max (len ("FILE" ), max (len (row ['file' ]) for row in table_data )) + 2
60+
61+ # Tablo çizimi
62+ separator = "|" + "=" * type_width + "|" + "=" * char_width + "|" + "=" * file_width + "|"
63+ header_line = f"| { 'TYPE' :<{type_width - 1 }} | { 'CHAR' :<{char_width - 1 }} | { 'FILE' :<{file_width - 1 }} |"
64+
65+ table = f"\n ANALYZING RESULTS\n \n { separator } \n { header_line } \n "
66+ table += "|" + "-" * type_width + "|" + "-" * char_width + "|" + "-" * file_width + "|\n "
67+
68+ for row in table_data :
69+ table += f"| { row ['type' ]:<{type_width - 1 }} | { row ['char' ]:<{char_width - 1 }} | { row ['file' ]:<{file_width - 1 }} |\n "
70+
71+ table += f"{ separator } \n \n TOTAL CHARS : { grand_total_char :,} \n TOTAL FILES : { grand_total_files :,} \n \n in mefamex.com\n "
72+
73+ return table
74+
75+
76+
77+ def analyze_directory (directory ):
78+ global text
79+ target_extensions = {'.html' , '.txt' , '.md' , '.js' , '.css' , '.py' }
80+ ignored_folders = {'.git' , '__pycache__' }
81+ grand_total_char , grand_total_files = 0 , 0
82+ results = {ext : {'files' : [], 'total_chars' : 0 } for ext in target_extensions }
83+
84+ for root , _ , files in os .walk (directory ):
85+ if any (ignored in root for ignored in ignored_folders ): continue
86+ print ("reading folder:" , root )
87+ for file in files :
88+ _ , ext = os .path .splitext (file )
89+ if ext in target_extensions :
90+ file_path = os .path .join (root , file )
91+ char_count = count_characters_in_file (file_path )
92+ results [ext ]['files' ].append (file_path )
93+ results [ext ]['total_chars' ] += char_count
94+
95+ print ("\n DONE.\n \n \n " )
96+
97+ # Toplam değerleri hesapla
98+ for ext in target_extensions :
99+ grand_total_char += results [ext ]['total_chars' ]
100+ grand_total_files += len (results [ext ]['files' ])
101+
102+ # Tablo oluştur
103+ table_output = create_table (results , grand_total_char , grand_total_files )
104+ text += table_output
105+
106+ print ("\n DONE.\n \n \n " )
107+
108+
109+
110+ if __name__ == "__main__" :
111+ current_dir = os .getcwd ()
112+ print (f"Analiz edilen dizin: { current_dir } " )
113+ time .sleep (3 )
114+
115+ analyze_directory (current_dir )
116+
117+ # Sonuçları yazdır
118+ for line in text .split ("\n " ):
119+ print (line )
120+ time .sleep (0.1 )
121+
122+ # Dosyaya kaydet
123+ filename = f"_folder_analysis_results.txt" #_{datetime.datetime.now().strftime('%Y-%m-%d %H.%M.%S')}.txt"
124+ with open (filename , "w" , encoding = "utf-8" ) as f : f .write (text )
125+
126+ print (f"\n \n Analysis results have been saved to '{ os .path .abspath (filename )} '." )
0 commit comments