循环遍历目录和子文件夹中的文件夹

时间:2017-09-01 08:40:37

标签: powershell

我有一个具有以下文件夹结构的目录:

  
      
  • BookingService      
        
    • DEV      
          
      • BookingService.config
      •   
    •   
    • UAT      
          
      • BookingService.config
      •   
    •   
    • LIVE      
          
      • BookingService.config
      •   
    •   
  •   
  • DriverService      
        
    • DEV      
          
      • DriverService.config
      •   
    •   
    • UAT      
          
      • DriverService.config
      •   
    •   
    • LIVE      
          
      • DriverService.config
      •   
    •   
  •   
  • 的AccountService      
        
    • DEV      
          
      • AccountService.config
      •   
    •   
    • UAT      
          
      • AccountService.config
      •   
    •   
    • LIVE      
          
      • AccountService.config
      •   
    •   
  •   

我想遍历每个文件夹和底层DEV,UAT,LIVE子文件夹以提取* .config文件的内容。

到目前为止,我已尝试过以下操作,但不断收到错误消息:Cannot process argument because the value of argument "path" is null。我该如何解决?

$branch = "C:\work\Services"
$targetEnv = "DEV"

Get-ChildItem -Path $branch | % { 
    cd $_.DirectoryName 
    . $_.FullName 
    ($path = Resolve-Path "$($_.DirectoryName\($targetEnv)*\*.config") 2> $null
    if ($path -ne $null)
    {
        # do some stuff here
    }
}

0 个答案:

没有答案