Fastruct 是一个轻量级的命令行工具,用于以清晰的树状结构展示目录内容。它会根据文件类型使用不同颜色进行标记,并显示每个文件的完整路径。
支持多种编程语言的源代码文件:
- C/C++ 家族 (
.cpp,.c,.h,.hpp,.cc,.cxx) - Python (
.py) - Java (
.java) - JavaScript (
.js) - Rust (
.rs) - Go (
.go) - Ruby (
.rb) - PHP (
.php) - Perl (
.pl) - Shell 脚本 (
.sh,.bash,.zsh)
- Windows: 根据扩展名识别 (
.exe,.bat,.cmd,.com) - Unix-like: 根据文件权限识别(具有执行权限的文件)
通过AUR来安装:
git clone https://aur.archlinux.org/fastruct.git
cd fastruct
makepkg -si- 从 Releases 页面下载最新版本的
fastruct-1.1.0-windows-x86_64.exe - 运行安装包,安装完成后,您需要设置PATH环境变量
- C++17 兼容的编译器
- GCC/G++ (若可能,建议)
git clone https://github.com/GuitaristRin/fastruct.git
cd fastruct
# Linux
g++ -std=c++17 -o fastruct fastruct.cpp
# Windows (MinGW)
g++ -std=c++17 -o fastruct.exe fastruct.cppfastruct [选项]| 选项 | 描述 |
|---|---|
-d <路径> |
指定起始目录(默认为当前目录) |
--depth <数值> |
设置最大递归深度(默认为无限) |
--nopath |
不在文件名后显示完整路径 |
--saveto [路径] |
将输出保存到指定文件或目录(若不指定路径,则默认保存到当前目录下的 fastruct_output.txt) |
fastruct输出示例:
project/
-subdir1
-file.txt /home/user/project/file.txt
-script.sh /home/user/project/script.sh
-main.cpp /home/user/project/main.cpp
fastruct -d /path/to/directory# 只显示当前目录内容(不进入子目录)
fastruct --depth 0
# 显示两层结构
fastruct --depth 2fastruct --nopath输出示例(与之前相比,文件名后不再显示完整路径):
project/
-subdir1
-file.txt
-script.sh
-main.cpp
# 保存到当前目录下的默认文件 fastruct_output.txt
fastruct --saveto
# 保存到指定文件
fastruct --saveto /home/user/output.txt
# 保存到指定目录(会在该目录下生成 fastruct_output.txt)
fastruct --saveto /home/user/output_dir/fastruct -d /home/user/projects --depth 3 --nopath --saveto ./struct.txt每一行代表一个文件或目录:
- 目录以
-开头,后跟黄色的目录名 - 文件以
-开头,后跟彩色文件名,最后(默认)是灰色的完整路径 - 当使用
--nopath时,文件名后不再显示路径
- 当目录层级深度超过 5 时,程序会发出警告并请求确认,防止因意外操作导致输出刷屏。
- 输出时,前缀的减号数量默认等于当前深度,但当实际深度超过警告阈值(5)时,超出的层级依然只显示 5 个减号,使结构更加清晰易读。
- 在 Windows 上使用时,确保终端支持 ANSI 颜色代码(Windows 10 及以上版本默认支持)
- 如果遇到权限不足的目录,程序会显示错误信息并继续处理其他目录
- 符号链接会被跳过,以避免循环引用
本项目采用 MIT 许可证。详见 LICENSE 文件。
Fastruct is a lightweight command-line tool for displaying directory contents in a clear tree structure. It uses different colors to mark files based on their type and displays the full path of each file.
Supports source code files for multiple programming languages:
- C/C++ Family (
.cpp,.c,.h,.hpp,.cc,.cxx) - Python (
.py) - Java (
.java) - JavaScript (
.js) - Rust (
.rs) - Go (
.go) - Ruby (
.rb) - PHP (
.php) - Perl (
.pl) - Shell Scripts (
.sh,.bash,.zsh)
- Windows: Recognized by file extension (
.exe,.bat,.cmd,.com) - Unix-like: Recognized by file permissions (files with execute permission)
Install via AUR:
git clone https://aur.archlinux.org/fastruct.git
cd fastruct
makepkg -si- Download the latest
fastruct-1.1.0-windows-x86_64.exefrom the Releases page - Run setup, after the installation, you may need to add the PATH
- C++17 compatible compiler
- GCC/G++ (recommended if possible)
git clone https://github.com/GuitaristRin/fastruct.git
cd fastruct
# Linux
g++ -std=c++17 -o fastruct fastruct.cpp
# Windows (MinGW)
g++ -std=c++17 -o fastruct.exe fastruct.cppfastruct [options]| Option | Description |
|---|---|
-d <path> |
Specify the starting directory (defaults to current directory) |
--depth <value> |
Set the maximum recursion depth (defaults to unlimited) |
--nopath |
Do not display the full path after the file name |
--saveto [path] |
Save output to a specified file or directory (if no path is given, defaults to fastruct_output.txt in the current directory) |
fastructSample Output:
project/
-subdir1
-file.txt /home/user/project/file.txt
-script.sh /home/user/project/script.sh
-main.cpp /home/user/project/main.cpp
fastruct -d /path/to/directory# Show only the current directory contents (do not enter subdirectories)
fastruct --depth 0
# Show two levels of structure
fastruct --depth 2fastruct --nopathSample Output (paths are no longer displayed after file names):
project/
-subdir1
-file.txt
-script.sh
-main.cpp
# Save to default file fastruct_output.txt in the current directory
fastruct --saveto
# Save to a specific file
fastruct --saveto /home/user/output.txt
# Save to a specific directory (fastruct_output.txt will be created there)
fastruct --saveto /home/user/output_dir/fastruct -d /home/user/projects --depth 3 --nopath --saveto ./struct.txtEach line represents a file or directory:
- Directory starts with
-followed by the directory name in yellow - File starts with
-followed by the colored filename, ending (by default) with the full path in gray - When
--nopathis used, the path is omitted after the filename
- If the directory depth exceeds 5, the program issues a warning and asks for confirmation to prevent unintentional flooding of the output.
- The number of dashes in the prefix is normally equal to the current depth. However, once the actual depth exceeds the warning threshold (5), the prefix remains at 5 dashes for deeper levels, keeping the output clean and readable.
- When using on Windows, ensure your terminal supports ANSI color codes (Windows 10 and above support this by default)
- If a directory with insufficient permissions is encountered, the program will display an error message and continue processing other directories
- Symbolic links are skipped to avoid circular references
This project is licensed under the MIT License. See the LICENSE file for details.