如何获取按文件夹名称排序的子文件夹及其文件的列表

发布于 2024-09-14 07:59:54 字数 790 浏览 4 评论 0原文

我可以使用 dir 命令行来获取子文件夹及其文件的列表(按文件夹名称排序,而不仅仅是文件名排序)吗?

使用

dir /s/b/o:gn > f.txt

我首先获取所有子文件夹,然后才获取所有子文件,例如:

 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”也可以位于列表末尾]

谢谢,

Atara

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 ?

using

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

But I want to get -

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" and "file01.txt" can also be at the end of the list]

Thanks,

Atara

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

紫竹語嫣☆ 2024-09-21 07:59:54

使用排序怎么样?

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 | sort

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

How about using sort?

dir /b /s | sort

Here's an example I tested with:


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 | sort

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

To just get directories, use the /A:D parameter:

dir /a:d /s /b | sort
拿命拼未来 2024-09-21 07:59:54

嗨,伙计,你为什么用这个?

dir /s/b/o:gn > f.txt (错误)

你不知道“/o”中的“g”是什么吗?

检查一下:http://www.computerhope.com/dirhlp.htm 或 dir / ?对于 dir help

你应该使用这个:

目录 /s/b/o:n > f.txt (右一个)

Hej man, why are you using this ?

dir /s/b/o:gn > f.txt (wrong one)

Don't you know what is that 'g' in '/o' ??

Check this out: http://www.computerhope.com/dirhlp.htm or dir /? for dir help

You should be using this instead:

dir /s/b/o:n > f.txt (right one)

今天小雨转甜 2024-09-21 07:59:54

dir /b /ad /s *.* 将满足您的要求。

dir /b /a-d /s *.* will fulfill your requirement.

南城旧梦 2024-09-21 07:59:54

将所有文件和文件夹的列表放入文本文件的命令如下:

例如:dir /b /s |排序>文件文件夹列表.txt

Command to put list of all files and folders into a text file is as below:

Eg: dir /b /s | sort > ListOfFilesFolders.txt

茶花眉 2024-09-21 07:59:54

在命令提示符下,转到您想要列表的主目录...并输入命令 tree /f

In command prompt go to the main directory you want the list for ... and type the command tree /f

岛歌少女 2024-09-21 07:59:54

如果您想使用 Powershell,我发现的最佳方法是:

Get-childitem -path "C:\your\path\here\" -recurse -name | out-file C:\your\path\to\textfile\here\files.txt

然后您将获得以文本文件形式写入的文件夹和子文件夹内的文件名。

Best way i found if you want to use Powershell:

Get-childitem -path "C:\your\path\here\" -recurse -name | out-file C:\your\path\to\textfile\here\files.txt

Then you will get the filenames inside the folder and subfolders written in a textfile.

神经大条 2024-09-21 07:59:54

创建一个 vbs 文件并复制下面的所有代码。将目录位置更改为您想要的任何位置。

Dim fso
Dim ObjOutFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")

ObjOutFile.WriteLine("Type,File Name,File Path")

GetFiles("YOUR LOCATION")

ObjOutFile.Close

WScript.Echo("Completed")

Function GetFiles(FolderName)
    On Error Resume Next

    Dim ObjFolder
    Dim ObjSubFolders
    Dim ObjSubFolder
    Dim ObjFiles
    Dim ObjFile

    Set ObjFolder = fso.GetFolder(FolderName)
    Set ObjFiles = ObjFolder.Files

    For Each ObjFile In ObjFiles
    ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
    Next

    Set ObjSubFolders = ObjFolder.SubFolders

    For Each ObjFolder In ObjSubFolders

        ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)


        GetFiles(ObjFolder.Path)
    Next

End Function

将代码保存为vbs并运行。你会在该目录中得到一个列表

create a vbs file and copy all code below. Change directory location to wherever you want.

Dim fso
Dim ObjOutFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")

ObjOutFile.WriteLine("Type,File Name,File Path")

GetFiles("YOUR LOCATION")

ObjOutFile.Close

WScript.Echo("Completed")

Function GetFiles(FolderName)
    On Error Resume Next

    Dim ObjFolder
    Dim ObjSubFolders
    Dim ObjSubFolder
    Dim ObjFiles
    Dim ObjFile

    Set ObjFolder = fso.GetFolder(FolderName)
    Set ObjFiles = ObjFolder.Files

    For Each ObjFile In ObjFiles
    ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
    Next

    Set ObjSubFolders = ObjFolder.SubFolders

    For Each ObjFolder In ObjSubFolders

        ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)


        GetFiles(ObjFolder.Path)
    Next

End Function

Save the code as vbs and run it. you will get a list in that directory

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文