使用 tree-node-cli 自動生成目錄樹結(jié)構(gòu)

一、安裝 Node 和 Git

下載 Node.jsGit,網(wǎng)上教程很多,這里不再贅述。

二、安裝 tree-node-cli

在項目的根文件夾下鼠標右鍵打開 Git Bash Here

image

輸入下面命令進行安裝:

npm install -g tree-node-cli
image

三、自動生成目錄樹結(jié)構(gòu)

輸入下面命令:

tree -L 4 -I "Scripts|Lib|pycache" > tree.md
image

解釋:

  • tree -L n 顯示項目的層級。n 表示層級數(shù)。比如你想要顯示項目的 4 層結(jié)構(gòu),可以用tree -L 4。
  • tree -I "Scripts|Lib|pycache" 表示要過濾的文件夾/目錄。
  • tree > tree.md 表示將結(jié)構(gòu)輸出到 tree.md 這個文件。

更多操作可以輸入 tree --help 進行查看:

Options:
  -V, --version             output the version number
  -a, --all-files           All files, include hidden files, are printed.
  --dirs-first              List directories before files.
  -d, --dirs-only           List directories only.
  -I, --exclude [patterns]  Exclude files that match the pattern. | separates alternate patterns. Wrap your entire pattern in double quotes. E.g. `"node_modules|coverage".
  -L, --max-depth <n>       Max display depth of the directory tree.
  -r, --reverse             Sort the output in reverse alphabetic order.
  -F, --trailing-slash      Append a '/' for directories.
  -h, --help                output usage information

查看 tree.md 文件里的內(nèi)容:

image

這樣就能直接復制內(nèi)容寫進 GitHub 項目里的 README 中了,超級方便,而且很有條理。

四、參考

使用tree生成目錄樹結(jié)構(gòu)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容