我曾经在linux中使用这样的路径,但是在Windows PowerShell中,我得到了以下错误
At line:1 char:10
+ ls {path1,path2}/*
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument
我尝试了dir {path1,path2}/*
,而不是ls {path1,path2}/*
,但丢弃了相同的错误!
您应该在正在工作的环境中使用适当的cmdlet/别名(请在Linux PowerShell上考虑ls
CC_4是指系统ls
而不是POSH GCI)
powershell允许通配符*?
(和范围[0-2]
)在多级别上,因此应该这样做:
Get-ChildItem -Path someverbose[12]dir* -Include *.ext1,*.ext2
以防路径的一部分完全不同,您必须提供一个数组:
Get-ChildItem -Path somethisdir*,somethatdir* -Include *.ext1,*.ext2
我认为您想要的是:
ls path1,path2 -recurse
path1和path2将需要是变量或引用的字符串。
这是一个示例
PS C:> ls "c:temptest1","c:temptest2" -recurse
Directory: C:temptest1
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/14/2019 10:29 AM test1subdir
Directory: C:temptest1test1subdir
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:29 AM 13 test1file.txt
Directory: C:temptest2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:30 AM 6 test2file.log
我知道这可能很疯狂,但是您可以创建一个几乎复制您要做的事情的函数:
function new-ls {
param([Parameter(Position=0)]
[string]$Path,
[Parameter(Position=1)]
[string[]]$Includes)
$StrMatch = ($Path | sls -pattern "^(.*?){(.*?),(.*?)}(.*?)$" -allmatches).matches.groups.value
$NewPaths = @(($StrMatch[1] + $StrMatch[2] + $StrMatch[4]), ($StrMatch[1] + $StrMatch[3] + $StrMatch[4]))
ls $NewPaths -include $Includes -recurse
}
# Running the code
PS C:temp> new-ls "c:temp{test1,test2}*"
Directory: C:temptest1test1subdir
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:29 AM 13 test1file.txt
Directory: C:temptest2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:30 AM 6 test2file.log
PS C:temp> new-ls "c:temp{test1,test2}*" "*.txt"
Directory: C:temptest1test1subdir
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:29 AM 13 test1file.txt
PS C:temp> new-ls "c:temp{test1,test2}*" "*.txt","*.log"
Directory: C:temptest1test1subdir
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:29 AM 13 test1file.txt
Directory: C:temptest2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/14/2019 10:30 AM 6 test2file.log