none
Shell Script: How to use recursive command to get the specific file path

    Question

  • I am using the below code to get the folder path of the "GatwayConfig.exe" file but after running the command it is throwing an error as "The term '\GatewayConfig.exe' is not recognized as the name of acmdlet, function, script file"

    $ConfigToolSearchString = 'GatewayConfig.exe'

    $global:ConfigToolLoc
    $ConfigToolDetails = ''
    $ConfigToolLoc = ''
    $ConfigToolDetails = Get-ChildItem -Path "C:" -Recurse | Where-Object { !$_PsIsContainer -and [System.IO.Path]::GetFileName($_.Name) -eq "GatewayConfig.exe" }
    write-host $ConfigToolDetails
    $ConfigToolLoc = $ConfigToolDetails.DirectoryName
    $ConfigToolLoc = $ConfigToolLoc + '\' + $ConfigToolSearchString

    please let me know the resolution.

    Thanks,

    Brijesh


    Friday, February 15, 2013 7:02 AM

Answers

  • You are doing too much:

    if($gwcfile=Get-ChildItem -Path C:\* -Recurse -include  GatewayConfig.exe){
         #file found
    }else{
         # file not found
    }


    ¯\_(ツ)_/¯


    Tuesday, February 19, 2013 6:46 PM