最近,我不得不向朋友发送我计算机上特定目录中所有文件和文件夹的列表,我花了一些时间来找出最好的解决方法。在尝试了各种方法之后,我能够创建一个漂亮的Excel 电子表格(Excel spreadsheet),其中包含文件和文件夹的所有数据以及文件大小、上次修改日期等附加信息。
在本文中,我将提到生成目录列表(directory listing)的两种主要方法:使用命令行(command line)或使用第三方程序。如果您的需求非常简单,命令行方法(command line method)是最简单的,不需要任何额外的工具。如果您需要更精美的报告,请查看免费软件实用程序。
命令行
因此,让我们先从命令行方法(command line method)开始,因为它很简单,并且对于阅读本文的 90% 的人来说可能已经足够了。要开始,请打开资源管理器并浏览(Explorer and browse)到要获取目录列表的文件(directory listing)夹上方的文件夹目录(folder directory)。
如果要打印C:Test MyTestFolder的(MyTestFolder)文件和文件夹列表(file and folder listing),则导航到 C:Test,按SHIFT 键(SHIFT key),然后右键单击MyTestFolder。继续并从菜单中选择在此处打开命令窗口。(Open command window here)
在命令提示符下(command prompt),您必须键入一个非常简单的命令:
dir >filename.txt
dir 命令(dir command)生成当前目录中的文件和文件夹列表,右尖括号(angle bracket)表示应该将输出发送到文件而不是屏幕上。该文件将在当前文件夹中创建,如果您使用记事本(Notepad)打开它,它将如下所示:
默认情况下,该命令将为您提供最后修改的日期/时间、文件大小、目录列表和实际文件名。如果您需要不同的信息,可以在命令中添加参数。
例如,如果您不想要所有这些额外信息,则可以使用以下命令仅打印文件和文件夹的名称:
dir /b >filename.txt
在上面的示例中,您会注意到有一个名为Word Stuff的文件夹,但输出并未(output doesn)列出该目录中的任何文件。如果要获取所有文件和文件夹的列表,包括当前目录的子目录,则可以使用以下命令:
dir /b /s >filename.txt
请注意,如果您想要完整的目录和子目录列表(directory and subdirectory listing)以及有关大小等的额外数据,您也可以删除 /b 。下面是dir /s >filename.txt的输出。
dir 命令(dir command)还有很多其他的命令行(command line)参数,在这里我不会提及,但是您可以在 Microsoft 的网站上查看它们的完整列表。(full list of them)使用额外的参数,您还可以显示文件属性(隐藏、压缩等)、显示文件所有权等。然后,您可以将数据导入Excel并选择制表符分隔,这样数据将被分成单独的列,而不是集中在一起。
第三方免费软件
目录列表和打印
打印目录列表的最佳实用程序之一是Directory List & Print。当您下载它时,您会注意到某些功能已被禁用。这是因为免费版不包括(version doesn)专业版(Pro version)中包含的所有选项。要解锁所有内容,您必须支付 20 美元。
但是,除非您真的需要每天打印目录列表,否则免费版本对任何人来说都绰绰有余。安装后,您必须首先选择要打印的目录。您还可以从右侧的收藏夹列表中进行选择(hand side)。
请注意,此时,您应该会在程序的底部文本窗口(text window)中看到预览的输出。我真的很喜欢这个,因为您可以使用不同的选项并立即看到结果更新。现在单击名为Selection的第二个选项卡。
默认情况下,提供子目录(Provide subdirectories)和提供文件(Provide files)被选中。这意味着它将打印出当前目录中的文件列表,并将包括当前目录中的所有文件夹。它不会列出子目录中的文件。如果你想这样做,你必须选中底部的通过子目录运行框。(Run through subdirectories)
如您所见,您可以在免费版本中包含创建日期(creation date)、修改日期、文件大小(file size)、路径等,但如果您想要文件所有者、文件属性等,则需要解锁软件。在下面的示例中,我检查了显示文件大小(Show file size)并通过子目录运行(Run through subdirectories)以获取此输出:
我将跳过第三个选项卡(过滤器(Filter)),因为它在免费版本中完全被禁用。付费版本有一些非常高级的过滤选项,但只有在你有数千或数百万个文件时才需要。在“输出(Output)”选项卡上,您可以选择要将列表导出到的位置。
您可以打印、复制到剪贴板或导出到Word 和 Excel(Word and Excel)。令人讨厌的是,他们在免费版本中禁用了复制到记事本并导出到文件。(Notepad and export)操作选项卡(Action tab)也被完全禁用,因此这里不再赘述。总体而言,该程序的免费版本做得很好,并且足以获得完整而详尽的目录列表。
凯伦的目录打印机
Karen 的目录打印机(Karen’s Directory Printer)已经很老了(2009 年),但在导出目录列表方面仍然做得很好。它没有Directory List & Print Pro那么多的选项,但与免费版本相比,它非常接近。
您必须先从“打印(Print)”选项卡或“保存到磁盘(Save to Disk)”选项卡中进行选择。两者完全相同,一个只是打印到打印机,另一个将输出保存到磁盘。可能(Probably)不需要两个单独的选项卡,但它是一个旧程序。
选择您的文件夹,然后选择是要仅打印文件名、仅打印文件夹名称,还是两者都打印。您还可以告诉它搜索子文件夹并将它们也打印出来。此外,您可以包含或排除系统文件、隐藏文件和只读文件。
单击显示网络(Show Network)复选框将允许您查看所有网络驱动器和共享并打印出它们的结构!这对于在服务器上具有文件夹共享的办公网络非常有用。
您还可以按文件名(file name)、文件扩展名(file extension)、文件大小(file size)、创建日期、修改日期等进行排序。您还可以放置文件过滤器(file filter),以便仅打印某些类型的文件,例如仅图像、声音文件、可执行文件、文档等。
最后,您可以从要包含在文件打印列表(file print list)中的大量属性中进行选择。默认情况下,它检查了一些我不关心(t care)的项目,例如属性、上次访问日期等。只需(Just)取消选中它们并确保单击“文件夹信息(Folder Info)”选项卡并在那里执行相同操作。
将文件保存到磁盘时,程序会插入一堆无用的注释,幸运的是,可以通过选中“省略注释行(Omit COMMENT Lines)”框将其删除。您还可以通过选中第二个框来删除显示该行是文件还是文件夹的列。(file or folder)
最后,该程序的另一个重要功能是它在您的资源管理器上下文(Explorer context)菜单中添加了一个选项,以便您只需右键单击任何文件夹并选择“使用 DirPrn 打印(Print with DirPrn)”。
除了我上面展示的内容之外,该软件真的没有什么其他的了。它在Windows 7和Windows 8上运行良好,非常棒。
因此,这些都是您可以根据需要使用尽可能多或尽可能少的信息免费生成目录列表的所有不同方式。(directory listing)如果您有任何问题,请发表评论。享受!
How to Print a List of Files in a Windows Directory
Recently, І hаd to send a frіend a list of all the files and folders in a particular directory on my computer and it took me some time to figure out the best way to gо about it. After playing aroυnd with variоus methods, I was able to create a nice looking Excel spreadsheet with all the data on the filеѕ and folderѕ plus additional info like the size of fіles, last modified date, etc.
In this article I’m going to mention the two main ways to generate a directory listing: using the command line or using a third-party program. If your needs are very simple, the command line method is the easiest and doesn’t require any additional tools. If you need a more fancy report, then check out the freeware utilities.
Command Line
So let’s start with the command line method first since it’s easy and will probably be enough for 90% of the people reading this article. To get started, open Explorer and browse to the folder directory above the folder that you want to get the directory listing for.
If you want to print out the file and folder listing for C:\Test\MyTestFolder, then navigate to C:\Test, press the SHIFT key and then right-click on the MyTestFolder. Go ahead and select Open command window here from the menu.
At the command prompt, you have to type a very simple command:
dir >filename.txt
The dir command generates a list of files and folders in the current directory and the right angle bracket says that the output should be sent to a file rather than onto the screen. The file will be created in the current folder and if you open it using Notepad, it’ll look like this:
By default, the command will give you the last modified date/time, the size of the files, the list of directories and the actual file names. If you want different information, you can add parameters to the command.
For example, if you don’t want all that extra information, you can print just the names of the files and folders using the following command:
dir /b >filename.txt
In the above examples, you’ll notice there is a folder called Word Stuff, but the output doesn’t list any of the files inside that directory. If you want to get a listing of all files and folders including subdirectories of the current directory, then you would use this command:
dir /b /s >filename.txt
Note that you can also get rid of /b if you want the full directory and subdirectory listing with the extra data on size, etc. Here is the output of dir /s >filename.txt below.
The dir command has a bunch of other command line parameters which I won’t mention here, but you can check out a full list of them on Microsoft’s website. Using the extra parameters, you can also show file attributes (hidden, compressed, etc), show file ownership and more. You can then import the data into Excel and choose tab-delimited so that the data will be separated into individual columns rather than being bunched into one.
Third-Party Freeware
Directory List & Print
One of the best utilities for printing directory listings is Directory List & Print. When you download it, you’ll notice that some of the features are disabled. That’s because the free version doesn’t include all the options that are included in the Pro version. To unlock everything, you’ll have to pay $20.
However, unless you really need to print out directory listings on a daily basis, the free version will be more than enough for just about anybody. Once you install it, you have to first choose the directory that you want to print out. You can also choose from a list of favorites on the right hand side.
Note that at this point, you should see the output previewed in the bottom text window of the program. I really like this because you can play around with the different options and see the results updated instantly. Now click on the second tab named Selection.
By default, Provide subdirectories and Provide files are checked. This means it’ll print out the list of files in the current directory and will include any folders also in the current directory. It will not list out the files that are in subdirectories. If you want to do that, you have to check the Run through subdirectories box at the bottom.
As you can see, you can include the creation date, modified date, file size, path, etc in the free version, but if you want file owner, file attributes, etc, you’ll need to unlock the software. In the example below, I checked Show file size and Run through subdirectories to get this output:
I’m going to skip the third tab (Filter) because it’s completely disabled in the free version. The paid version has some pretty advanced filtering options, but really only needed if you have thousands or millions of files. On the Output tab, you can choose where you want to export the listing out to.
You can print it, copy to clipboard, or export out to Word and Excel. To be annoying, they disabled copy to Notepad and export to file in the free version. The Action tab is also completely disabled so won’t go into it here. Overall, the free version of the program does a great job and more than enough to get a complete and thorough listing of a directory.
Karen’s Directory Printer
Karen’s Directory Printer is pretty old (2009), but still does a great job of exporting out directory listings. It doesn’t have as many options as Directory List & Print Pro, but compared to the free version, it’s quite close.
You have to pick from the Print tab or the Save to Disk tab first. Both are exactly the same, one just prints to a printer and the other saves the output to disk. Probably didn’t need two separate tabs for that, but it’s an old program.
Pick your folder and choose whether you want to print file names only, folder names only, or both. You can also tell it to search sub folders and print them out also. In addition, you can include or exclude system, hidden and read-only files.
Clicking on the Show Network checkbox will allow you to see all network drives and shares and print out their structures too! This is great for office networks that have folder shares on servers.
You can also sort by file name, file extension, file size, date created, date modified and more. You can also put a file filter so that only certain types of files are printed, such as images only, sound files, executables, documents, etc.
Finally, you can choose from a large number of attributes that you want to include in your file print list. By default, it has a couple of items checked that I don’t care about like attributes, date last accessed, etc. Just uncheck them and make sure to click on the Folder Info tab and do the same there.
When saving the file to disk, the program inserts a bunch of useless comments, which can thankfully be removed by checking the Omit COMMENT Lines box. You can also get rid of the column that shows whether the row is a file or folder by checking the second box.
Finally, one other great feature of the program is that it adds an option to your Explorer context menu so that you can simply right-click on any folder and choose “Print with DirPrn“.
There really isn’t much else to the software than what I have shown above. It runs fine on Windows 7 and Windows 8, so that’s great.
So those are all the different ways you can generate a directory listing for free with as much or as little information as needed. If you have any questions, post a comment. Enjoy!