Complete the code to list all files in the directory.
import os files = os.[1]('.') print(files)
The os.listdir function lists all files and folders in the given directory.
Complete the code to delete a file named 'old.log'.
import os os.[1]('old.log')
The os.remove function deletes a file given its path.
Fix the error in the code to rename 'temp.log' to 'backup.log'.
import os os.[1]('temp.log', 'backup.log')
The os.rename function renames or moves a file from the old name to the new name.
Fill both blanks to create a dictionary with file names as keys and their sizes as values for files larger than 1000 bytes.
import os files = os.listdir('.') sizes = {file: os.path.[1](file) for file in files if os.path.[2](file) and os.path.[1](file) > 1000}
os.path.getsize returns the size of a file. os.path.isfile checks if the path is a file.
Fill all three blanks to filter files with '.log' extension, get their sizes, and keep only those larger than 5000 bytes.
import os files = os.listdir('.') log_files = {file: os.path.[1](file) for file in files if file.endswith('[2]') and os.path.[3](file) > 5000}
Use getsize to get file size, filter files ending with '.log', and check size greater than 5000 bytes.