Learn Programming تعلم البرمجة
26.8K subscribers
256 photos
8 videos
40 files
342 links
Get started on your programming journey with our tutorials. Learn how to code and develop your skills in various languages with our beginner-friendly platform.
For advertising and cooperation or to buy the channel
Contact us: @tellmy_bot
Download Telegram
برنامج بلغة بايثون يقوم بكشف الملفات ذات الحجم الكبير في مجلد معين:

import os

def find_large_files(directory, min_size_mb=100):
    """
    Finds files in the given directory that are larger than the specified minimum size in megabytes.
   
    Args:
        directory (str): The directory to search for large files.
        min_size_mb (int, optional): The minimum file size in megabytes. Default is 100 MB.
   
    Returns:
        dict: A dictionary where the keys are the file paths and the values are the file sizes in bytes.
    """
    large_files = {}
   
    for root, dirs, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            file_size = os.path.getsize(file_path)
            if file_size > min_size_mb * 1024 * 1024:
                large_files[file_path] = file_size
   
    return large_files

# Example usage
directory_to_search = "/path/to/your/directory"
large_files_dict = find_large_files(directory_to_search, min_size_mb=100)

if large_files_dict:
    print("Large files found:")
    for file_path, file_size in large_files_dict.items():
        print(f"{file_path} - {file_size / (1024 * 1024):.2f} MB")
else:
    print("No large files found in the specified directory.")

أوضح كيفية استخدام هذا البرنامج:

1. يستخدم دالة find_large_files لتحديد الملفات ذات الحجم الكبير في مجلد محدد.
2. يأخذ هذه الدالة مدخلان:
   - directory: المسار إلى المجلد الذي ترغب في البحث فيه عن الملفات الكبيرة.
   - min_size_mb: الحد الأدنى للحجم الملف بالميجابايت (الافتراضي هو 100 ميجابايت).
3. الدالة تعود بقاموس حيث المفاتيح هي مسارات الملفات والقيم هي أحجام الملفات بالبايت.
4. في المثال الموجود في نهاية الكود، يتم البحث في المسار /path/to/your/directory عن الملفات التي تزيد أحجامها عن 100 ميجابايت.
5. إذا تم العثور على ملفات كبيرة، يتم طباعة مسار كل ملف وحجمه بالميجابايت.

يمكنك تعديل المسار وحد الحجم الأدنى حسب احتياجاتك. كما يمكنك إضافة المزيد من الخصائص والخيارات إلى هذا البرنامج حسب ما تحتاجه.


لائحة الوسوم بالعربية:

#بايثون #كشف_الملفات_الكبيرة #حجم_الملفات #تحليل_الملفات #البرمجة_بلغة_بايثون

لائحة الوسوم بالإنجليزية:

#Python #FindLargeFiles #FileSize #FileAnalysis #PythonProgramming

🎯فضلا شارك المنشور مع اصدقاءك المهتمين.



@SuDevelopers | SUBSCRIBE
❤7👍3