如何获取子文件夹及其文件的列表,按文件夹名称排序 [英] How to get a list of sub-folders and their files, ordered by folder-names
本文介绍了如何获取子文件夹及其文件的列表,按文件夹名称排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用dir命令行获取子文件夹及其文件的列表,按文件夹名称排序,而不只是文件名?
Can I use "dir" command-line to get a list of sub-folders and their files, ordered by folder-names, and not just file-names ?
使用
dir / s / b / o:gn> f.txt
dir /s/b/o:gn > f.txt
我首先得到所有子文件夹,然后是所有子文件,例如:
I first get all sub-folders and only then all sub files, e.g.:
d:\root0\root1\folderA
d:\root0\root1\folderB
d:\root0\root1\file00.txt
d:\root0\root1\file01.txt
d:\root0\root1\folderA\fileA00.txt
d:\root0\root1\folderA\fileA01.txt
d:\root0\root1\folderB\fileB00.txt
d:\root0\root1\folderB\fileB01.txt
但我想要 -
d:\root0\root1\file00.txt
d:\root0\root1\file01.txt
d:\root0\root1\folderA
d:\root0\root1\folderA\fileA00.txt
d:\root0\root1\folderA\fileA01.txt
d:\root0\root1\folderB
d:\root0\root1\folderB\fileB00.txt
d:\root0\root1\folderB\fileB01.txt
[file00.txt和file01.txt也可以在列表的结尾]
["file00.txt" and "file01.txt" can also be at the end of the list]
谢谢,
Atara
推荐答案
如何使用 sort
?
dir /b /s | sort
下面是我测试的例子:
dir / s / b / o:gn
d:\root0
d:\root0\root1
d:\root0\root1\folderA
d:\root0\root1\folderB
d:\root0\root1\file00.txt
d:\root0\root1\file01.txt
d:\root0\root1\folderA\fileA00.txt
d:\root0\root1\folderA\fileA01.txt
d:\root0\root1\folderB\fileB00.txt
d:\root0\root1\folderB\fileB01.txt
dir / s / b |排序
d:\root0
d:\root0\root1
d:\root0\root1\file00.txt
d:\root0\root1\file01.txt
d:\root0\root1\folderA
d:\root0\root1\folderA\fileA00.txt
d:\root0\root1\folderA\fileA01.txt
d:\root0\root1\folderB
d:\root0\root1\folderB\fileB00.txt
d:\root0\root1\folderB\fileB01.txt
要获取目录,请使用 / A:D
参数:
dir /a:d /s /b | sort
这篇关于如何获取子文件夹及其文件的列表,按文件夹名称排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文