从目录中查找特定扩展名

时间:2016-11-10 13:22:45

标签: powershell

我有一个根目录,其中包含几个子目录,其中一个目录中有我想要的function GetFileNames { $folders = Get-ChildItem "c:\myFolder" $filename = [System.IO.Directory]$folders[0].GetFiles($folders[0].FullName, "*.ps1", "AllDirectories") } 文件:

c:\myFolder

所以在这条路径中:.ps1 file我有几个文件夹,我想要做的就是取第一个文件夹,在这个文件夹里找到我的$filename。 目前,此// this would work because it's wrapped inside parentheses and has a parent component content = ( <View> <Text>Just this line works</Text> <Text>This doesn't work</Text> </View> ) // this works because the components are an array content = [ <Text key="1">Just this line works</Text>, <Text key="2">This doesn't work</Text> ] 值为空。

1 个答案:

答案 0 :(得分:0)

您可以选择第一项并再次调用Get-ChildItem cmdlet:

function GetFileNames
{
    Get-ChildItem "c:\myFolder" -Directory | 
        select -first 1 | 
        Get-ChildItem -Filter '*.ps1' -recurse | 
        select -expand Name
}

但这对我来说有点尴尬。你想要实现什么目标?