You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批处理自动化adb push时目标路径变量为空及特殊路径处理问题

Fixing Your Android File Transfer Batch Script

Hey there! Let's get your batch script working properly—we'll tackle the variable typo first, then handle those tricky paths with spaces, single quotes, and shared folders.

The Core Issues in Your Original Script

  • Variable Name Typo: You wrote %loaction% instead of %location%—that's exactly why your target path showed up empty!
  • Incorrect Quoting: Using single quotes (') around paths doesn’t play nice with Windows batch or the adb command, especially when dealing with spaces, single quotes in filenames, or network shared paths.

Corrected Batch Script

Here's the fixed version that addresses all these problems:

@echo off
setlocal enabledelayedexpansion

set /p filename="Enter the full path and name of the file to transfer: > "
set /p location="Enter the target path on your Android device (e.g., /sdcard/Documents/): > "

:: Optional: Preview the command before execution
echo Preview: adb push "%filename%" "%location%"

:: Execute the actual adb push command
adb push "%filename%" "%location%"

echo Transfer attempt finished! Check above for adb feedback.
pause

Key Improvements Explained

  • Fixed Variable Typo: We corrected loaction to location so the target path variable is properly referenced.
  • Double Quotes for Paths: Windows batch and adb both recognize double quotes (") as the standard way to wrap paths with spaces, special characters (like ' in that's right.txt), or network shared paths (e.g., \\mysharedfolder\text files\). This ensures the entire path is treated as a single value.
  • setlocal enabledelayedexpansion: This helps avoid parsing issues with any special characters in user-input paths, making the script more robust.
  • Optional Preview Line: Added a preview of the command so you can verify it’s correct before running the actual transfer.

Quick Usage Tips

  • Make sure adb is added to your system’s PATH, or save this script in the same folder as your adb.exe file.
  • For Android target paths, use forward slashes (/) instead of backslashes (e.g., /sdcard/Downloads/—adb will handle this automatically, but it’s good practice).
  • Ensure your Android device has USB debugging enabled and is connected to your computer before running the script.

内容的提问来源于stack exchange,提问作者user3906610

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 11:37:43