7

I want to check if there is a certain file inside a directory in my android device.

I use the following line in my windows batch

adb shell find /mnt/sdcard/koinoxrista -name Bill.txt

I want to do something if the file exists and something else if file does not exist.

How can I do this?

Alex P.
  • 30,437
  • 17
  • 118
  • 169
kosbou
  • 3,919
  • 8
  • 31
  • 36

4 Answers4

9

Find command is not supported in adb shell. This command will also show you hidden files adb shell ls -laR | grep filename

Misha
  • 433
  • 4
  • 10
  • 3
    This won't give you the file path, it will only reports if it exists. To get the path I would instruct grep to also report every directory crawled by `ls`, like this: `adb shell ls -laR | grep -E "filename|:$"` – volpato Oct 23 '14 at 13:58
  • @volpato, I've tried to use your suggestion, but still I can't get full path – ransh May 10 '16 at 06:08
2

The find command is supported in Android since version 6.0 (Mashmallow).

This is because it's including Toybox since then.

https://en.wikipedia.org/wiki/Toybox

jox
  • 2,218
  • 22
  • 32
1

I am afraid that the Android emulator does not provide with the 'find' program.

  • This is entirely true - android does not ship find, and only recently (possibly after this writing) started shipping grep, so why downvote it? – Chris Stratton Aug 07 '14 at 14:24
1

When you know the exact file name you do not need to use any extra commands like find to look for it. Simply check if it exists using built-in shell facilities:

adb shell "[ -f /mnt/sdcard/koinoxrista/Bill.txt ] && echo 'found'"
Alex P.
  • 30,437
  • 17
  • 118
  • 169