adb: error: cannot stat '%~f1': No such file or directory
There is no expansion for %1 in %~f1 for any registry arguments:
Arguments:
%1, %D, %H, %I, %L, %S, %V, %W
Not Work/Expand:
%~nx1, %~nxD, %~nxH, %~nxI, %~nxL, %~nxS, %~nxV, %~nxW
Often we find "%1" in the commands associated with file types
(HKEY_CLASSES_ROOT\FileType\shell\open\command).
In Windows 9x through 2000 (and possibly XP) this would evaluate
to the short notation of the fully qualified path of the file of type FileType.
To get the long file name, use "%L" instead of "%1".
When using right click on file -> ADB_Push_to_Phone, the selected file has to be passed to your .bat, it doesn't come automatically, it is first "passed" from the register to .bat as an argument.
You are already treating the path, passing it as complete by right click to windows registry in "%V", so you can use "%~1", since the argument received in your bat file.
@echo off
cd /d "%~d0"
adb.exe connect 192.168.0.103:5555
adb.exe push "%~1" /sdcard/
adb.exe disconnect
In the Windows registry (or .reg file) use:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\ADB_Push_to_Phone]
[HKEY_CLASSES_ROOT*\shell\ADB_Push_to_Phone\command]
@="C:\Windows\System32\cmd.exe" /q /c "D:\Tools\CMD\ADB_PUSH_TO_PHONE.cmd" "%L""
Your bat can go straight to where the executable is, without the need to edit the path for each drive/volume change, use cd /d "drive_where_your_bat_is":
@echo off
cd /d "%~d0"
adb.exe connect 192.168.0.103:5555
adb.exe push "%~1" /sdcard/
adb.exe disconnect
- Or use
drive_where_your_bat_is: + \adb.exe
@echo off
%~d0\adb.exe connect 192.168.0.103:5555
%~d0\adb.exe push "%~1" /sdcard/
%~d0\adb.exe disconnect