有时您需要确切知道某个文件夹中存储了多少文件或文件夹。无论(Whether)是工作还是自己的统计,如果你有Windows 设备(Windows device),有很多方法可以找到这些信息。因此,如果您想知道如何计算目录中的文件数,请继续阅读。以下是在Windows 10(Windows 10)中使用文件资源管理器(File Explorer)、PowerShell和命令提示符(Command Prompt)计算文件夹内元素的四种方法:
注意:(NOTE:)为了说明对目录中的文件、文件夹和子文件夹进行计数的方法,我们使用的是Windows 10。但是,这些方法也应该适用于旧版本的Windows,例如Windows 8.1和Windows 7。
1.如何使用文件资源管理器计算文件夹中的文件(File Explorer)
您要计算存储在某个文件夹及其所有子文件夹中的所有文件夹和文件吗?查找此信息的一种简单方法是使用所选文件夹的“属性(Properties)”窗口。打开文件资源管理器(Open File Explorer),浏览到您的文件夹,然后右键单击或按住文件夹的图标。在上下文菜单上,选择Properties。或者,选择文件夹并按(folder and press)键盘上的Alt + Enter键。
当“属性(Properties)”窗口打开时,Windows 10 会自动开始计算所选目录中的文件和文件夹。您可以看到包含(Contains)字段中显示的文件和文件夹的数量。
2.如何使用PowerShell统计文件夹中的文件(PowerShell)
PowerShell提供了一种对存储在文件夹中的文件和子文件夹进行计数的最佳方法之一。打开 PowerShell 并(Open PowerShell and head)前往该文件夹的位置。为此,请运行命令cd [path],其中[path]是您文件夹的路径。
例如,我们想要计算在位于“E:OneDrive”中的("E:OneDrive,")Documents文件夹中找到的文件和子文件夹,因此我们需要运行cd "E:OneDriveDocuments"。
如果要计算该目录中的文件和文件夹,请运行以下命令:(Get-ChildItem | Measure-Object).Count。请注意,它不递归工作,它只计算第一级元素。
如果您只想计算父文件夹中的文件夹(parent folder),请运行以下命令:(Get-ChildItem -Directory | Measure-Object).Count。
如果您只想计算文件夹中的文件,请运行以下命令:(Get-ChildItem -File | Measure-Object).Count。
如果要递归计算父文件夹(parent folder)中的文件夹和/或文件,请将Recurse参数添加到前面的命令中,如下所示:
- 递归计算文件夹中的所有文件和子文件夹:(Get-ChildItem -Recurse | Measure-Object).Count
- 仅递归计算目录中的子文件夹:(Get-ChildItem -Recurse -Directory | Measure-Object).Count
- 仅递归计算文件夹中的文件:(Get-ChildItem -Recurse -File | Measure-Object).Count
注意:(NOTE:)递归计数意味着您计算文件夹包含的所有文件和子文件夹,而不仅仅是文件夹树(folder tree)第一级的文件和文件夹。
3.如何使用命令提示符(Command Prompt)(cmd)计算文件夹中的文件
您还可以使用命令提示符(Command Prompt)。要计算文件夹中的文件夹和文件,请打开命令提示符(Command Prompt)并运行以下命令:dir /a:-d /s /b "Folder Path" | find /c ":"。
例如,我们想计算“E:OneDriveDocuments”文件夹中的文件和子文件夹,所以我们必须运行dir /a:-d /s /b "E:OneDriveDocuments" | find /c ":"。
如果要计算文件夹中的子文件夹,请运行以下命令:dir /a:d /s /b "Folder Path" | find /c ":"。在我们的示例中,这将是dir /a:d /s /b "E:OneDriveDocuments" | find /c ":"。
4.如何使用文件资源管理器计算文件夹中的文件(File Explorer)
这个方法涉及到File Explorer的使用,但我们把它留到最后,因为它不能递归地工作。它只计算文件夹树(folder tree)第一级的文件和文件夹,即使这些文件夹中包含其他文件和文件夹。即便如此,它在某些情况下也可能有用。
打开文件资源管理器并浏览(Open File Explorer and browse)到存储要计数的项目的文件夹。存储在其中的项目总数(文件和文件夹)显示在文件资源管理器(File Explorer's)用户界面的左下角。
如果您只想计算文件夹中存储的一些文件或文件夹,请选择所有文件或文件夹,然后查看文件资源管理器(File Explorer)界面的左下方。它应该显示所选项目的数量。
而已!
您知道计算文件夹中文件的其他方法吗?
如果您想从Windows 计算机(Windows computer)中确切知道一个文件夹中有多少个文件和文件夹,现在您知道该怎么做了。如您所见,有几种方法可以获取此信息,因此您可以选择最适合的方法。如果您有任何疑问,或者您知道其他查找此信息的方法,请随时在下方给我们留言。
How to count the files in a folder using PowerShell, CMD, or File Explorer
There аre times when you need to know exactly how many files or folders are stored inѕide a certain folder. Whether for work or yоur own statistics, if you haνe a Windows device, there are quite а few wayѕ to find this information. So, if you've ever wondered how to count the number of filеs in a directory, read оn. Here are four methods for countіng the elementѕ found inside a folder, in Windows 10, using File Explorer, PowerShell, and the Command Prompt:
NOTE: To illustrate the methods for counting files, folders, and subfolders inside a directory, we're using Windows 10. However, the methods should also work in older versions of Windows, such as Windows 8.1 and Windows 7.
1. How to count the files in a folder, using File Explorer
Do you want to count all the folders and files stored inside a certain folder and all its subfolders? An easy method to find this information is to use the Properties window of the selected folder. Open File Explorer, browse to your folder, and right-click or press-and-hold on the folder's icon. On the contextual menu, select Properties. Alternatively, select the folder and press the Alt + Enter keys on your keyboard.
When the Properties window opens, Windows 10 automatically starts counting the files and folders inside the selected directory. You can see the number of files and folders displayed in the Contains field.
2. How to count the files in a folder using PowerShell
PowerShell offers one of the best ways to count the files and subfolders stored inside a folder. Open PowerShell and head to the location of the folder. To do that, run the command cd [path], where [path] is your folder's path.
For example, we want to count the files and subfolders found in our Documents folder, located in "E:OneDrive," so we need to run cd "E:OneDriveDocuments".
If you want to count the files and folders inside that directory, run this command: (Get-ChildItem | Measure-Object).Count. Note that it does not work recursively, it only counts the first-level elements.
If you want to count only the folders inside your parent folder, run this command: (Get-ChildItem -Directory | Measure-Object).Count.
If you want to count only the files in the folder, run this command: (Get-ChildItem -File | Measure-Object).Count.
If you want to recursively count folders and/or files in your parent folder, add the Recurse parameter to the previous commands, as follows:
- Recursively count all files and subfolders in a folder: (Get-ChildItem -Recurse | Measure-Object).Count
- Recursively count only subfolders in a directory: (Get-ChildItem -Recurse -Directory | Measure-Object).Count
- Recursively count only files in a folder: (Get-ChildItem -Recurse -File | Measure-Object).Count
NOTE: Recursive counting means that you count all the files and subfolders contained by a folder, not just the files and folders on the first level of the folder tree.
3. How to count the files in a folder, using Command Prompt (cmd)
You can also use the Command Prompt. To count the folders and files in a folder, open the Command Prompt and run the following command: dir /a:-d /s /b "Folder Path" | find /c ":".
For example, we wanted to count the files and subfolders in our "E:OneDriveDocuments" folder, so we had to run dir /a:-d /s /b "E:OneDriveDocuments" | find /c ":".
If you want to count the subfolders in a folder, run this command: dir /a:d /s /b "Folder Path" | find /c ":". In our example, that would be dir /a:d /s /b "E:OneDriveDocuments" | find /c ":".
4. How to count the files in a folder, using File Explorer
This method involves the use of File Explorer, but we left it until last because it doesn't work recursively. It counts only the files and folders on the first level of the folder tree, even if these folders contain other files and folders inside. Even so, it might be useful in certain situations.
Open File Explorer and browse to the folder where the items you want to count are stored. The total number of items (both files and folders) stored inside is displayed in the lower-left corner of File Explorer's user interface.
If you want to count only some of the files or folders stored inside your folder, select all of them and look at the bottom left side of the File Explorer interface. It should display the number of selected items.
That's it!
Do you know other methods to count the files in a folder?
If you want to know exactly how many files and folders are inside a folder from your Windows computer, now you know how to do it. As you've seen, there are a couple of ways to get this information, so you can choose whichever fits best. If you have questions, or if you know of other ways to find this information, don't hesitate to leave us a comment below.