Count Files
Imagine you are part of a big project, and your team uses different types of files for different tasks. You have
.py
files for the Python code, .txt
files for the notes, .csv
files for data. The files are in various directories and subdirectories. One day, you are given the task to find out how many Python files exist in a specific directory and all its subdirectories. You decide to write a Python script to automate this task.You are to create a script that will accept two parameters: the directory path and the file extension. The script should then recursively search the directory and all its subdirectories, and count the number of files with the specified extension.
The input of the program contains two lines. The first line contains the directory path and the second line contains the file extension (without the dot).
The program should print a single integer - the number of files with the given extension in the directory and all its subdirectories.
Input | Output |
documents/python-projects
py | 2 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB