0
0
Operating Systemsknowledge~30 mins

File attributes and operations in Operating Systems - Mini Project: Build & Apply

Choose your learning style9 modes available
File attributes and operations
📖 Scenario: You are managing files on your computer. Each file has details like its name, size, and permissions. You want to organize this information clearly to understand and control your files better.
🎯 Goal: Create a simple list of files with their attributes, add a filter to find files larger than a certain size, and then list those files with their details.
📋 What You'll Learn
Create a list called files containing dictionaries for each file with keys: 'name', 'size' (in KB), and 'permissions' (a string like 'rwx').
Create a variable called size_limit set to 100 to filter files larger than 100 KB.
Use a list comprehension to create a new list called large_files containing only files from files with 'size' greater than size_limit.
Add a final step to print the names and sizes of the files in large_files.
💡 Why This Matters
🌍 Real World
Organizing and managing files on a computer by checking their size and permissions helps keep data safe and easy to find.
💼 Career
Understanding file attributes and how to filter or list files is important for system administrators, IT support, and anyone managing computer storage.
Progress0 / 4 steps
1
Create the initial list of files with attributes
Create a list called files with these exact dictionaries: {'name': 'report.docx', 'size': 120, 'permissions': 'rw-'}, {'name': 'photo.jpg', 'size': 85, 'permissions': 'r--'}, and {'name': 'script.py', 'size': 150, 'permissions': 'rwx'}.
Operating Systems
Need a hint?

Use a list with dictionaries. Each dictionary must have keys 'name', 'size', and 'permissions' with the exact values given.

2
Set the size limit for filtering files
Create a variable called size_limit and set it to 100 to use as the threshold for filtering files by size.
Operating Systems
Need a hint?

Just create a variable named size_limit and assign it the number 100.

3
Filter files larger than the size limit
Use a list comprehension to create a new list called large_files that includes only the dictionaries from files where the 'size' value is greater than size_limit.
Operating Systems
Need a hint?

Use a list comprehension with file for file in files if file['size'] > size_limit.

4
Display the names and sizes of large files
Add a for loop to go through large_files and print each file's 'name' and 'size' in the format: File: <name>, Size: <size>KB.
Operating Systems
Need a hint?

Use a for loop with file as the variable and print using an f-string.