1

I am new to Powershell, and I want to check if specfic path exits in Android emulator, I need to use it in PowerShell. I try to print the result of adb shell ls /data/local/tmp/, it will list files, and if the path does not exist, it will show No such file, but how to detect it? Any one knows?

newszer
  • 440
  • 1
  • 4
  • 23

2 Answers2

1

Actually I have found my way to check it

 $checkPathExists = (adb shell ls $pathToCheck) | Out-String
if($checkPathExists -match 'No such file or directory')
{
    Write-Host "$pathToCheck path does not exist. Try to create it ..." -ForegroundColor Red
    adb shell mkdir $pathToCheck
    if(!$?)
    {
        Write-Host "Creating $pathToCheck folder failed!" -ForegroundColor Red
        exit 1
    }
}
newszer
  • 440
  • 1
  • 4
  • 23
0

Validaitng paths are done using the Test-Path cmdlet on Windows/OSX/Linux.

Get parameter, examples, full and Online help for a cmdlet or function

(Get-Command -Name Test-Path).Parameters
Get-help -Name Test-Path -Examples
Get-help -Name Test-Path -Full
Get-help -Name Test-Path -Online

Then just use If/Then, Try/Catch to perform actions based on your needs.

postanote
  • 15,138
  • 2
  • 14
  • 25