Created
February 10, 2025 05:35
-
-
Save AIFahim/6cd85ad1405e76cce328ded7b7573fd6 to your computer and use it in GitHub Desktop.
get file structure from codebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def get_file_structure(root_path, indent=""): | |
""" | |
Generates a string representation of the file and directory structure | |
rooted at the given path. | |
Args: | |
root_path: The path to the root directory. | |
indent: The current indentation level (used for recursive calls). | |
Returns: | |
A string representing the file structure. | |
""" | |
structure = "" | |
if os.path.isdir(root_path): | |
structure += indent + os.path.basename(root_path) + "/\n" | |
for item in os.listdir(root_path): | |
item_path = os.path.join(root_path, item) | |
structure += get_file_structure(item_path, indent + "│ ") | |
else: | |
structure += indent + os.path.basename(root_path) + "\n" | |
return structure | |
def main(): | |
project_root = os.path.dirname(os.path.abspath(__file__)) # Get path of the current script | |
file_structure = get_file_structure(project_root) | |
print(file_structure) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment