如何在Windows中将目录列表打印或保存到文件

Occasionally, you might want to print or save a list of the files in a directory. Windows doesn’t feature a simple way to do this from its interface, but it’s not too hard to accomplish.

有时,您可能需要在目录中打印或保存文件列表。 Windows并没有一种从其界面执行此操作的简单方法,但是并不太难实现。

Printing a directory listing is probably not something you’ll need to do often, but it can occasionally be useful. Maybe you just want a quick list to compare with another directory. Maybe you need to generate a printed list for some work reason. Or maybe you just want a saved list of your installed apps. Whatever your reasons, printing or saving a directory list isn’t too difficult. We’re going to show you a quick way to do it from the Command Prompt (or PowerShell), and a third-party tool that makes things a little easier if you have to do it often.

打印目录列表可能不是您经常需要执行的操作,但有时会很有用。 也许您只想将一个快速列表与另一个目录进行比较。 出于某些工作原因,也许您需要生成打印清单。 或者,也许您只想要保存的已安装应用程序列表。 无论您出于什么原因,打印或保存目录列表都不太困难。 我们将向您展示从命令提示符(或PowerShell)执行此操作的快速方法,以及一个第三方工具,该工具可以使您不得不经常执行的操作变得容易一些。

使用Windows PowerShell打印目录列表 (Print A Directory List By Using Windows PowerShell)

Printing or saving a directory listing using PowerShell is an easy, straightforward process. First you need to open the Command Prompt and get to the directory for which you want to print the contents. You can do this in one of two ways.

使用PowerShell打印或保存目录列表是一个简单,直接的过程。 首先,您需要打开命令提示符并进入要打印其内容的目录。 您可以通过以下两种方式之一来执行此操作。

The first (and easiest) is to right-click the folder and choose the “Open PowerShell Window Here” command from the context menu. If you already have a PowerShell window open, you could also just navigate to the folder using the cd command.

第一种(也是最简单的方法)是右键单击该文件夹,然后从上下文菜单中选择“在此处打开PowerShell窗口”命令。 如果已经打开PowerShell窗口,则也可以使用cd命令导航到该文件夹​​。

Note: This procedure works exactly the same way whether you use PowerShell or Command Prompt, so use whichever you feel most comfortable with.

注意:无论您使用PowerShell还是命令提示符,此过程的工作方式都完全相同,因此请使用您觉得最合适的方法。

At the prompt, type the following command (replacing “filename.txt” with whatever you want the resulting file to be named), and then press Enter:

在提示符下,键入以下命令(将“ filename.txt”替换为您想要命名结果文件的名称),然后按Enter:

dir > filename.txt

Windows creates a file in that same directory by whatever name you chose.

Windows会根据您选择的名称在同一目录中创建一个文件。

When you open the file in Notepad, or in your favorite text editor or word processor, you’ll see the same directory listing you would see had you just used the dir command alone at the prompt.

在记事本中或在喜欢的文本编辑器或文字处理器中打开文件时,将看到与仅在提示符处仅使用dir命令时看到的目录列表相同的目录。

If you prefer just a list of the filenames themselves, you can modify the previous command with the /b switch:

如果您只喜欢文件名列表本身,则可以使用/b开关修改前面的命令:

cmd /r dir /b > filename.txt

Note: the cmd /r part of this command tells PowerShell to execute the command as typed and then exit. If you’re using the Command Prompt, you don’t need to add the cmd /r part of this command and would just type dir /b > filename.txt .

注意:此命令的cmd /r部分告诉PowerShell执行键入的命令,然后退出。 如果使用命令提示符,则无需添加此命令的cmd /r部分,只需键入dir /b > filename.txt

That command gives you a text file that looks more like this:

该命令为您提供了一个文本文件,看起来像这样:

And one more little bonus tip. If you find yourself needing to create a file with directory listings often, we’ve written about a little hack that lets you copy a directory’s file list to your clipboard with just a right-click. That makes things a little more convenient, and also lets you paste the resulting file list into any type of document you want.

还有一点小技巧。 如果您发现自己经常需要创建带有目录列表的文件,我们已经写了一篇关于如何使目录文件列表复制到剪贴板的小技巧, 只需单击鼠标右键 。 这使事情变得更加方便,并且还使您可以将结果文件列表粘贴到所需的任何类型的文档中。

使用第三方工具打印目录列表 (Print A Directory List Using a Third-Party Tool)

If you don’t mind installing a third-party tool to get the job done, Directory List & Print makes things even easier by letting you generate directory listings that you can customize, save as files, or print.

如果您不介意安装第三方工具来完成工作,则“ 目录列表和打印”将使您生成可自定义,另存为文件或打印的目录列表,从而使事情变得更加轻松。

The free version Directory List & Print will likely do everything you need, especially if you’re just looking for a way to print basic lists of files in single directories. If you need even more power, the Pro version ($22) adds the ability to include a huge number of metadata and Windows file properties, specify a recursion depth for subdirectories, provides additional sorting abilities, and more.

免费版本的目录列表和打印可能会满足您的所有需求,特别是如果您只是在寻找一种在单个目录中打印文件基本列表的方法时。 如果您需要更多功能,则Pro版本(22美元)增加了包含大量元数据和Windows文件属性的功能,为子目录指定了递归深度,还提供了其他排序功能,等等。

Directory List & Print is available as both an installable or a portable app, so choose whichever is right for you.

目录列表和打印既可以作为可安装的应用程序 ,也可以作为便携式应用程序使用 ,因此请选择适合您的选项。

Using the app is reasonably straightforward. On the “Directory” tab, choose the directory for which you want to list the contents. You can choose from a hierarchical folder view or a list of favorite folders.

使用该应用程序相当简单。 在“目录”选项卡上,选择要列出其内容的目录。 您可以从分层文件夹视图或收藏夹文件夹列表中选择。

On the “Columns” tab, choose the columns you want displayed in your list on the left and click the “Add” button (the right arrow) to add those columns. Use the up and down arrows at left to adjust the positions of the columns. And click the “Create/Update File List” button at any time to see how your list is shaping up.

在“列”选项卡上,选择要在左侧列表中显示的列,然后单击“添加”按钮(向右箭头)以添加这些列。 使用左侧的向上和向下箭头调整列的位置。 并随时单击“创建/更新文件列表”按钮,以查看列表的状态。

Choose any advanced options you want from the “Display” and “Filter” tabs (we’re going to send you to the app’s help files for details on those), and then, on the “Output” tab, choose how to generate your list. You can print it, copy it to the clipboard, or save it in a number of popular formats.

从“显示”和“过滤器”选项卡中选择所需的任何高级选项(我们将把您发送到应用程序的帮助文件以获取有关这些信息的详细信息),然后在“输出”选项卡上选择如何生成您的清单。 您可以将其打印,复制到剪贴板或以多种常用格式保存。

Another especially handy feature of Directory List & Print is that you can add an option to the context menu for folders, allowing you to quickly open that folder in the app. To do this, you must first run Directory List & Print as administrator. Right-click the .exe file and select the “Run as administrator” option.

目录列表和打印的另一个特别方便的功能是,您可以在文件夹的上下文菜单中添加一个选项,从而可以在应用程序中快速打开该文件夹。 为此,您必须首先以管理员身份运行目录列表和打印。 右键单击.exe文件,然后选择“以管理员身份运行”选项。

After the app loads, open the “Setup” menu, and then choose the “Add to Directory Context Menu” option.

应用加载后,打开“设置”菜单,然后选择“添加到目录上下文菜单”选项。

Now, to generate a quick listing, just right-click a folder and choose the “Open in Directory List + Print” command from the context menu.

现在,要生成快速列表,只需右键单击一个文件夹,然后从上下文菜单中选择“在目录列表中打开+打印”命令。

You can also drag and drop a directory from Windows Explorer onto the program window to quickly generate a listing of that directory.

您还可以将目录从Windows资源管理器拖放到程序窗口中,以快速生成该目录的列表。

翻译自: https://www.howtogeek.com/98064/how-to-print-or-save-a-directory-listing-to-a-file/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值