使用 Get-ChildItem -Exclude 或 -Include 不返回任何内容 [英] Using Get-ChildItem -Exclude or -Include returns nothing

查看:54
本文介绍了使用 Get-ChildItem -Exclude 或 -Include 不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 C: 目录中有一个包含许多文件的列表.如果我尝试对其运行 -Exclude ,则不会得到任何回报.与 -Include 相同.如果我使用过滤器,它会返回我期望返回的内容.我不明白它应该做什么吗?

I have a list in my C: directory that has many files. If I try to run an -Exclude on it, I get no returns. Same with -Include. If I use filter it returns what I expected to get back. Am I not understanding what it should be doing?

这是我正在运行但什么也没得到的示例:

Here is an example of what I am running and getting nothing:

Get-ChildItem -Path C: -Exclude "*.txt"

我什么也得不到.如果我跑

I get nothing back. If I run

Get-Childitem -filter "*.txt"

我拿回来了:

  Mode                LastWriteTime         Length Name                                                                               
----                -------------         ------ ----                                                                               
-a----        11/7/2007   8:00 AM          17734 eula.1028.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1031.txt                                                                      
-a----        11/7/2007   8:00 AM          10134 eula.1033.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1036.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1040.txt                                                                      
-a----        11/7/2007   8:00 AM            118 eula.1041.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1042.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.2052.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.3082.txt                                                                      
               7/7/2016   8:50 AM             93 HaxLogs.txt                                                                        
-a----         7/8/2016   8:30 AM              0 Test.txt 

推荐答案

Get-ChildItem -Path "C:\*" -Include "*.txt"

这个关于 -Include 应该如何工作的例子会给你你期望的结果.请注意,我还在路径参数中提供了一个通配符,以将路径明确定义为根 C: 中的任何文件",而不是C:"本身.

This example, of how -Include should work, will give you the results you were expecting. Note that I provided a wildcard in the path parameter as well, to explicitly define the path as "any file in the root C:" as opposed to "C:" itself.

来源:https://technet.microsoft.com/library/hh849800.aspx

此链接中的示例 3,以防它失效(请注意此处路径中的通配符):

Example 3 from this link, in case it goes defunct (note the wildcard in path here, as well):

C:\> Get-ChildItem –Path "C:\Windows\Logs\*" -Include "*.txt" -Exclude "A*"

这篇关于使用 Get-ChildItem -Exclude 或 -Include 不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆