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?

10
  • codewiki.wikidot.com/shell-script:if-else Commented Jan 17, 2018 at 6:14
  • I need to run in powershell, yours answer is for shell Commented Jan 17, 2018 at 6:17
  • you have powershell installed on your android device? Commented Jan 17, 2018 at 6:20
  • No, I use adb shell command Commented Jan 17, 2018 at 6:20
  • so you use unix shell, read the link i posted above Commented Jan 17, 2018 at 6:21

2 Answers 2

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
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.