A script compatible with both zsh
and bash
to generate a Markdown file outlining the folder and file structure of the directory where the script is executed. The generated structure is presented in a readable Markdown format for easy documentation and sharing.
This script generates a Markdown file, structure.md
, detailing the folder and file hierarchy of the directory in which it is executed. The script excludes itself and its output file from the generated structure, making it ideal for documenting repositories, projects, or file collections.
- Compatible with bash and zsh
- Recursively scans folders and files starting from the script’s directory
- Outputs a well-structured Markdown file with:
- 📂 Folder icons
- 📄 File icons
- Dynamically adjusts indentation for nested structures
- Automatically excludes the script file and the generated Markdown file
- Operating System: macOS or Linux
- Shell: bash or zsh
- Tools Required:
printf
cd
basename
These utilities are included in most Unix-based operating systems.
- Save and execute the scripts in the chosen directory:
- Save the zsh or bash script in the folder with the files to process
- Make it executable:
chmod +x ./directory-structure-generator.zsh
resp.chmod +x directory-structure-generator.sh
- Run the script:
./directory-structure-generator.zsh
resp../directory-structure-generator.sh
- View the output:
- The script generates a
structure.md
file in the same directory. Open it with a text or Markdown viewer
- The script generates a
- Script Execution Detection:
- Identifies whether the script is run as a shell command or a script file
- Target Folder and Output File Setup:
- Automatically sets the target folder to the script’s directory
- Defines the output Markdown file as
structure.md
- Recursive Directory Traversal:
- Iterates over all items in the folder recursively
- Adds folder and file names to the Markdown file with appropriate indentation and icons
- Exclusion Rules:
- Excludes the script itself and the output file from the generated structure
- Permission Denied: Ensure the script has executable permissions:
chmod +x ./directory-structure-generator.zsh
resp.chmod +x ./directory-structure-generator.sh
- Empty Output File: Verify that the directory contains files and is not empty
- File Not Found Errors: Confirm that required commands (
basename
,printf
, etc.) are installed and available
Contributions are welcome! Please follow these steps:
- Fork this repository
- Create a feature branch:
git checkout -b feature-branch
- Commit your changes:
git commit -m "Add feature"
- Push the branch:
git push origin feature-branch
- Submit a pull request
Please ensure all changes are well-documented and tested.
Suggestions for improvements are highly encouraged! Please ensure that your contributions adhere to the project’s coding standards and include appropriate documentation.
This project is licenced under the MIT Licence. You are free to use, modify, and distribute this project in compliance with the licence terms.