Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: dir_count.py
- # Author: Jeoi Reqi
- """
- Directories Count Script
- This script reads the directory path from a specified folder ('test') in the
- same directory and counts the number of subfolders in the directory. It
- utilizes a function, count_directories, to perform the directory counting operation.
- Requirements:
- - Python 3
- Usage:
- 1. Save the 'test' folder in the same directory as the script.
- 2. Replace 'test' with the actual folder name in the script if needed.
- 3. Run the script.
- 4. The script will display the number of subfolders in the specified directory.
- """
- import os
- def count_directories(path):
- """Count the number of subfolders in a directory.
- Args:
- path (str): Directory.
- Returns:
- int: Number of subfolders.
- """
- return sum(os.path.isdir(os.path.join(path, folder)) for folder in os.listdir(path))
- def main():
- # Specify the folder path
- folder_path = 'test' # Replace 'test' with the actual folder name if needed
- # Count subfolders
- directory_count = count_directories(folder_path)
- # Display the result
- print(f"Number of subfolders in the directory: {directory_count}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement