avatar

目錄
【CMD】tree command 文件夾樹狀結構,導出目錄樹至txt檔

方法一

STEP 1

cd 、空格、然後 drag 目標 folder 至 CMD

cmd
cd <folderpath>

STEP 2

隨意起名,以下例子把導出檔案命名為 output.txt

cmd
tree /a /f > ouput.txt

生成的 txt 內容類似這樣

Code
C:.
| helloword.docx
| hello.xlsx
|
+---folder-1
| hellooooo.md
|
+---folder-2
| lalalala.docx
| wawawa.ptt
|
+---sub-folder
helloooo.png

方法二

語法

cmd
tree /f > ouput.txt

生成的 txt 內容類似這樣

Code
C:.
│ helloword.docx
│ hello.xlsx

├─folder-1
│ hellooooo.md

└─folder-2
│ lalalala.docx
│ wawawa.ptt

└─sub-folder
helloooo.png

Options meaning:

  • /a Display the tree using standard ASCII characters.
  • /b Display the full pathname of each directory, without any of the line-drawing characters.
  • /d Display file and directory descriptions.
  • /f Display files as well as directories.
  • /h Display hidden as well as normal directories. If you combine /h and /f, hidden files are also displayed.
  • /t Display the time and date for each directory. If you combine /t and /f, the time and date for each file will also be displayed.
    • /T:c Creation date and time.
    • /T:w Last modification (“write”) date and time (default).
  • /z Display the size of each file. /z without a /f will display the subdirectory tree sizes.

純列出,不樹狀

語法

bash
dir /s /b> ouput.txt

生成的 txt 內容類似這樣

Code
C:\Users\helloword.docx
C:\Users\hello.xlsx
C:\Users\folder-1
C:\Users\folder-2

純列出,不樹狀,只有檔案名

語法

bash
dir /b /a-d> ouput.txt

生成的 txt 內容類似這樣

Code
helloword.docx
hello.xlsx
folder-1
folder-2

References: https://jpsoft.com/help/tree.htm


如果您喜歡我的文章,歡迎幫我在下面按5下讚!感謝您的鼓勵和支持!

文章作者: ouoholly
文章鏈接: https://ouoholly.github.io/post/command-folder-directory-tree-structure/
版權聲明: 本博客所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。歡迎「部份引用」與介紹(如要全文轉貼請先留言詢問),轉載引用請註明來源 ouoholly 的倉庫,謝謝!

評論