在 Windows 系统中批量导出文件名到 txt 文本,有 CMD 和 PowerShell 两种方式。以下是完整的命令对照表和参数说明。
dir /b /a:-d
dir /b
dir /b /s /a:-d
dir /b /a:-d > list.txt
dir /b /s /a:-d > list.txt
Get-ChildItem -File | Select-Object -ExpandProperty Name > list.txt
Get-ChildItem -File -Recurse | Select-Object -ExpandProperty FullName > list.txt
Get-ChildItem -File -Recurse | Select-Object -ExpandProperty Name > list.txt
ls -fi > list.txt
ls -fi -r > list.txt
| 场景 | CMD 命令 | PowerShell 命令 |
|---|---|---|
| 只显示文件名 | dir /b /a:-d | Get-ChildItem -File | Select-Object -ExpandProperty Name |
| 递归所有子文件夹 | dir /b /s /a:-d | Get-ChildItem -File -Recurse |
| 保存到 txt | > list.txt | > list.txt |
| 最简写法 | dir /b > list.txt | ls -fi > list.txt |
推荐:日常使用推荐 PowerShell 简写版 ls -fi > list.txt,递归用 ls -fi -r > list.txt,简单直观。
数据来源:豆包AI助手整理,2026年5月
上一篇:苹果直营店 vs 授权第三方维修:核心区别与选择指南(2026)
下一篇:没有了