Python Script Coding
Python programming provides built-in functions for file system interaction and time handling, facilitating rapid file handling, error management, and simplified data processing. The script in Figure 4 (Appendix) implements a systematic procedure for navigating through directories, examining files, and producing an exhaustive list according to predetermined criteria.
Module Import
In Figure 1 below, os and datetime modules handle file system interaction and temporal data manipulation.

Creating a List of Files in a Loop
In Figure 2, the create_list_of_files function takes two parameters: Parameter_1, the root_folder, and Parameter_2, the predefined_minimum_file_size. Parameter_1 denotes the initial location from which the file search is initiated. Parameter_2 is the minimum file size requirement for results inclusion in the Results.txt file. The try-except block is used for error handling, enclosing potential errors within it.

The create_list_of_files function utilizes the with statement to attempt to open the file for writing purposes (‘w’). Any IOError instances are handled by a try-except block, which is essential for generating informative error messages without exposing unnecessary code in the event of file-processing issues.
The fundamental line in the loop is “for root, _, files in os.walk(root_folder):” which are tuples containing information about each directory visited. The “root, _, files” unpacks the tuple returned by os.walk into three variables, including root, _, and files. The root variable contains the full path to the current directory in the loop, and the files variable stores a list of filenames within the current directory. The create_list_of_files condition is set on the line (file_size > predefined_minimum_file_size) to compare files within the inner loop.
The subsequent lines of code process only files that exceed the specified minimum size. The create_list_of_files function is implemented to retrieve the data needed for the Results.txt file as the outcome. The script leverages functions from the os and datetime modules to retrieve the filename, file size, and creation time, which are appended to the “Results.txt” file (Martelli et al., 2023). In Figure 3, the create_list_of_files function is debugged in the “if name == “main”:” statement, which signifies the initiation of the script’s execution. When the Python script runs, the user is prompted to enter values for Parameter_1 and Parameter_2.

Required Environment to Run the Script
A Python interpreter with Python 3 or any subsequent version compatible must be installed on the system. The code uses standard libraries such as os and datetime, which are usually included with Python installations. Still, it is recommended to double-check their availability in the Python environment.
The user running the program must have permission to view and read files in the selected root folder, as the program interacts with the file system to traverse directories, read file metadata, and generate the “Results.txt” file. The program requires a terminal for user participation because the script prompts for input on the root folder and the minimum file size. Please enter a valid directory path and a numeric value for the minimum file size, as guided in the demo clip. Meeting these environmental requirements ensures the Python program runs smoothly, enabling practical exploration and description of files in the chosen directory.
Program Running Guide
The following steps constitute a guide to running the program with a predefined root directory.
- First, the demo shows the script and the root directory containing the subdirectories and the files.
- The root_file directory in the example: C:UsersComputerDesktopProgram
- The Program folder contains three subdirectories: Subfolder_1, Subfolder_2, and Subfolder_3. Each subfolder contains files of different sizes.
- The root directory path is Parameter_1: “C:Users ComputerDesktopProgram.”
- The next step provides Parameter_2 as the predefined_minimum_file_size, which is 1 byte to show all the files in the subdirectories.
- The script is rerun, providing the root directory and a minimum file size of 1000000 bytes.
- In both cases, the Results.txt file is populated with the filtered files with details: file name, size, and date created in that order.
For this specific case, you are supposed to save the provided code snippets in a file named w5_firstname_lastname.py (replace with your names). Create a folder, then create subdirectories, and place files of different sizes in each subdirectory. Note the file dimensions in the subdirectories and determine the appropriate minimum byte filter.
Execute the w5_firstname-lastname.py file, which will prompt for the root directory path as Parameter_1 (“C:UsersComputerDesktopProgram” in the example) – unique in your case. The next step is to provide the predefined_minimum_file_size, which, in the demo clip, is 10000 bytes. The Results.txt file should contain the filtered files with their specific details, in the requested order: file name, size, and date created.
Reference
Martelli, A., Ravenscroft, A. M., Holden, S., & McGuire, P. (2023). Python in a nutshell. O’Reilly Media.
Appendix
