Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: file_count.py
- # Author: Jeoi Reqi
- """
- File Count Script
- This script searches recursively in the 'test' directory (in the same directory
- as the script) and counts the number of files. It utilizes a function, count_files,
- to perform the file counting operation.
- Requirements:
- - Python 3
- Usage:
- 1. Save the script in the same directory as the 'test' folder.
- 2. Run the script.
- 3. The script will display the number of files in the 'test' directory.
- """
- import os
- def count_files(path):
- """Count the number of files in a directory recursively.
- Args:
- path (str): Directory.
- Returns:
- int: Number of files.
- """
- count = 0
- for root, dirs, files in os.walk(path):
- count += len(files)
- return count
- def main():
- # Specify the directory path
- directory_path = 'test' # Replace 'test' with the actual directory name if needed
- # Count files
- file_count = count_files(directory_path)
- # Display the result
- print(f"Number of files in the '{directory_path}' directory: {file_count}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement