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?
-
codewiki.wikidot.com/shell-script:if-elsepskink– pskink2018-01-17 06:14:47 +00:00Commented Jan 17, 2018 at 6:14
-
I need to run in powershell, yours answer is for shellnewszer– newszer2018-01-17 06:17:21 +00:00Commented Jan 17, 2018 at 6:17
-
you have powershell installed on your android device?pskink– pskink2018-01-17 06:20:11 +00:00Commented Jan 17, 2018 at 6:20
-
No, I use adb shell commandnewszer– newszer2018-01-17 06:20:39 +00:00Commented Jan 17, 2018 at 6:20
-
so you use unix shell, read the link i posted abovepskink– pskink2018-01-17 06:21:20 +00:00Commented Jan 17, 2018 at 6:21
|
Show 5 more comments
2 Answers
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
}
}
Comments
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.