【问题标题】:Get-ChildItem not listing files on Win Server 2003 but works fine on XPGet-ChildItem 未在 Win Server 2003 上列出文件,但在 XP 上工作正常
【发布时间】:2011-05-02 16:14:04
【问题描述】:

我正在尝试根据 cash_st_export*.txt 过滤器返回文件列表,但它不起作用!如果我在 XP 工作站上的默认 Powershell 工作目录中运行 gci *.dll,它可以正常工作。

PS C:\Program Files\iNovah 2 [Test]\WebServices\iNovah2WebService\ExportFiles> 
gci cash_st_export*.txt

PS C:\Program Files\iNovah 2 [Test]\WebServices\iNovah2WebService\ExportFiles> 
gci *.txt

PS C:\Program Files\iNovah 2 [Test]\WebServices\iNovah2WebService\ExportFiles> 
ls


Directory: C:\Program Files\iNovah 2 [Test]\WebServices\iNovah2WebService\ExportFiles


Mode                LastWriteTime     Length Name                                                                                               
----                -------------     ------ ----                                                                                               
d----          4/7/2011   2:23 PM            Archive                                                                                            
-a---         3/24/2011   6:30 PM          0 cash_sei_export_03242011_183015278.txt                                                             
-a---         3/25/2011   6:30 PM        294 cash_sei_export_03252011_183047903.txt                                                             
-a---         3/28/2011   6:30 PM        462 cash_sei_export_03282011_18302584.txt                                                              
-a---         3/29/2011   6:30 PM          0 cash_sei_export_03292011_183040422.txt                                                             
-a---         3/30/2011   9:38 AM        336 cash_sei_export_03302011_093800868.txt                                                             
-a---         3/30/2011   6:30 PM          0 cash_sei_export_03302011_18300400.txt                                                              
-a---         3/31/2011   2:04 PM          0 cash_sei_export_03312011_140407388.txt                                                     

【问题讨论】:

    标签: powershell get-childitem


    【解决方案1】:

    试试这个:

    gci * -包括 cash_st_export*.txt

    无论如何,ls的结果中似乎不存在现金st导出,而是现金sei导出。


    类似线程here

    也检查MS doc.


    我现在已经在我的 W2K8 服务器上测试了 gci 并且工作正常。 只有在不使用force 的情况下使用include 时,才需要使用*

    gci * -include 添加*.txt

    使用这个:

    gci 添加*.txt

    其实是一样的:

    gci -path 添加*.txt

    所有这些都适用于 Powershell v2.0 和(我认为)1.0。

    注意:您在评论中的解决方法仍然是指 sei 文件。

    【讨论】:

    • 目录列表很大,下面还有 cash_st_export*.txt 文件。但为了澄清,我跑了:“gci . -include cash_sei_export*.txt”,它没有返回任何结果。
    • 我能够将它拼凑起来以实现我的结果:gci | where-object { $_.Name -match "cash_sei" } 我要让它保持开放状态,看看是否有人能解释为什么我必须求助于它才能使其工作。
    • 我发现当使用Include参数而不使用Recurse参数时,路径必须指向内容,而不是容器。尝试新的编辑。
    猜你喜欢
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2011-12-26
    • 2011-09-11
    • 2014-02-24
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    相关资源
    最近更新 更多