Provide a python 3 script to scan all files on a system regardless of OS, and place the…
- User
Provide a python 3 script to scan all files on a system regardless of OS, and place the names/mod time/file extension/size in MB in an easy to read csv file. Ignore system files and program files.
Assistant
Sure, here is a Python 3 script that scans all files on a system regardless of OS, and places the names/mod time/file extension/size in MB in an easy to read CSV file. It ignores system files and program files.
import os import sys import csv # Create a list of all files in the current directory files = [] for root, dirs, files in os.walk("."): for file in files: files.append(os.path.join(root, file)) # Create a list of system files and program files system_files = [".DS_Store", "Thumbs.db"] program_files = ["*.exe", "*.dll", "*.bat", "*.cmd"] # Create a list of files to scan files_to_scan = [] for file in files: if not file in system_files and not file in program_files: files_to_scan.append(file) # Create a CSV file to write the results to csv_file = open("file_list.csv", "w", newline="") csv_writer = csv.writer(csv_file) # Write the header row to the CSV file csv_writer.writerow(["Name", "Mod Time", "File Extension", "Size (MB)"]) # Write the data for each file to the CSV file for file in files_to_scan: mod_time = os.path.getmtime(file) file_extension = os.path.splitext(file)[1][1:] size = os.path.getsize(file) / (1024 * 1024) csv_writer.writerow([file, mod_time, file_extension, size]) # Close the CSV file csv_file.close()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.