I'd like to check whether a file exists on my Android device, and if not - to push it. What is the syntax for doing so using adb on batch? Something like:
if exist ./sdcard/file.any do echo "exists"
else adb push file.any ./sdcard/
I'd like to check whether a file exists on my Android device, and if not - to push it. What is the syntax for doing so using adb on batch? Something like:
if exist ./sdcard/file.any do echo "exists"
else adb push file.any ./sdcard/
I know this is kinda old but how about something around the lines of:
I am using this for a very similar scenario which works for me. Thought I'd share.
Running in a command prompt window
if /?
orhelp if
outputs the help pages for internal command if.The command processor is not very tolerant on syntax. An
else
branch is only possible with using parentheses. The true branch must have(
which must be on same line as commandif
separated by a space from second compare string.The closing
)
for true branch can be on same line as opening(
or on a different line.The keyword
else
must be on same line as closing)
of the true branch after a space.If round brackets are used also for the else branch, opening
(
must be on same line aselse
separated with a space from the keyword.The keyword
do
is completely wrong here as it is a keyword for command FOR.Some of the working variants.
Everything on one line with as less spaces as possible (hard to read):
Everything on one line with more spaces for easier reading:
Condition on first line, true branch on second line, else branch without parentheses on third line:
Each part of the entire condition on separate lines:
There are more variants possible, but they are all horrible to read.
It is best to use second or fourth variant as those 2 are the best for reading.
I recommend to use always fourth variant if an else branch is used, too.
.\
at beginning of file name / directory name could be omitted.And the directory separator on Windows is the backslash character.
NOTE: I don't know if
if exist ./sdcard/file.any
or.\sdcard\file.any
works at all. The question does not contain any information aboutPATH
andPATHEXT
, etc.So the answer covers only the IF syntax mistake, not how to check for existence of a file on any Android device with any Android version connected with whatever device drivers and data storage accessing protocols are used for accessing the device.