Script: Send files to Android device over USB
Posted: 20 Jun 2013 18:05
Hi all,
This script allows you to select a folder on your computer and send it, and all the files in subfolders, to a location on your Android device.
It uses Android Debugging Bridge so you will need to install that.
https://developer.android.com/sdk/index.html
Make sure to registered adb,exe in your PATH variable or code the absolute location in the script yourself. If this project takes off I will probably expand it with my regular easy to configure interface.
Also, You can only copy to a location on your Android device that already exists. Meaning, You can not copy to /sdcard/myfolder/folder1/ until you have created that folder first on your tablet/phone. It's an easy fix, but like I said below, I'm too lazy to do it right now.
How it works:
1. Select the folder you want to transfer in Xyplorer
2. Input the path to which you want to transfer the folder in the dialogue (Default is /sdcard/)
3. adb transfers your files.
NOTE: You need to enable ADB debugging under developer options in your Android device's Settings.
http://www.androidcentral.com/how-enabl ... android-42
No fancy post this time. It's 25 degrees here in Germany with 85% humidity. That is all
Here is the code:
This script allows you to select a folder on your computer and send it, and all the files in subfolders, to a location on your Android device.
It uses Android Debugging Bridge so you will need to install that.
https://developer.android.com/sdk/index.html
Make sure to registered adb,exe in your PATH variable or code the absolute location in the script yourself. If this project takes off I will probably expand it with my regular easy to configure interface.
Also, You can only copy to a location on your Android device that already exists. Meaning, You can not copy to /sdcard/myfolder/folder1/ until you have created that folder first on your tablet/phone. It's an easy fix, but like I said below, I'm too lazy to do it right now.
How it works:
1. Select the folder you want to transfer in Xyplorer
2. Input the path to which you want to transfer the folder in the dialogue (Default is /sdcard/)
3. adb transfers your files.
NOTE: You need to enable ADB debugging under developer options in your Android device's Settings.
http://www.androidcentral.com/how-enabl ... android-42
No fancy post this time. It's 25 degrees here in Germany with 85% humidity. That is all
Here is the code:
Code: Select all
"_Initialize"
{
// Configuration .ini file
global $g_ConfigurationFile;
$g_ConfigurationFile = "<xyscripts>\AndroidTransfer.ini";
// Execution and buffer files
global $g_ExecutionFile;
$g_ExecutionFile = "<xyscripts>\AndroidTransfer.bat";
// Configuration keys
global $g_ScriptVersion;
$g_ScriptVersion = '0.1';
if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
// Load keys
} else {
msg <<<#
Script is not configured.
The configuration wizard will assist you.
#;
sub "_Configure";
}
}
"_Configure"
{
global $g_ConfigurationFile;
global $g_ScriptVersion;
msg <<<#
This wizard configures the script for first use. To edit the configuration file click "Edit Configuration" after launching the script. If the configuration file is not found or you upgrade to a new version of this script the wizard will appear automatically.
The configuration file is located at:
$g_ConfigurationFile
#;
// Delete old configuration file
delete (0, 0, "$g_ConfigurationFile");
// Define parameters
// Write configuration to disk
$Configuration = <<<#
[Configuration]
ScriptVersion=$g_ScriptVersion
#;
writefile ("$g_ConfigurationFile", "$Configuration", o, t);
msg <<<#
Configuration completed.
#;
}
"Send Folder Content"
{
global $g_SendFolder;
$g_SendFolder = get ('SelectedItemsPathNames', '|', 'a');
global $g_LocalRoot;
$g_LocalRoot = getpathcomponent ("$g_SendFolder", 'path');
if ($g_LocalRoot == getpathcomponent ("$g_LocalRoot", 'drive'){
$g_LocalRoot = getpathcomponent ("$g_LocalRoot", 'drive').':';
}
global $g_DeviceRoot;
$g_DeviceRoot = input ( , 'Define Android device folder to send to', '/sdcard/', 's', , , );
// List with all absolute paths
global $g_SendFolderSubTree;
sub "_GetSendFolderSubTree";
sub "_MkdirSendFolderSubTree";
sub "_GetSendFiles";
sub "_PushSendFolderFiles";
}
"_GetSendFolderSubTree"
{
global $g_SendFolder;
global $g_SendFolderSubTree;
$g_SendFolderSubTree = folderreport ('dirs', 'r', "$g_SendFolder", 'r', , '|');
$g_SendFolderSubTree = $g_SendFolderSubTree.'|'.$g_SendFolder;
$g_SendFolderSubTree = formatlist ("$g_SendFolderSubTree", 'e', '|', );
}
"_MkdirSendFolderSubTree"
{
global $g_SendFolderSubTree;
global $g_ExecutionFile;
delete ('0', '0', "$g_ExecutionFile");
global $g_LocalRoot;
global $g_DeviceRoot;
foreach ($Folder, $g_SendFolderSubTree, '|'){
$Folder = replace ("$Folder", "$g_LocalRoot", "$g_DeviceRoot", '0', , );
$Folder = replacelist ("$Folder", '/,\,\\,/\,\/', '/', ',' '0');
$Folder = regexreplace ("$Folder", '//', '/', '0');
writefile ("$g_ExecutionFile",'adb shell mkdir -p "'.$Folder.'"'."<crlf>", 'a', 't');
}
run ("$g_ExecutionFile", , '1', '1');
}
"_GetSendFiles"
{
global $g_SendFolder;
global $g_SendFiles;
$g_SendFiles = folderreport ('files', 'r', "$g_SendFolder", 'r', , '|');
}
"_PushSendFolderFiles"
{
global $g_SendFiles;
global $g_ExecutionFile;
delete ('0', '0', "$g_ExecutionFile");
global $g_LocalRoot;
global $g_DeviceRoot;
foreach ($File, $g_SendFiles, '|'){
writefile ("$g_ExecutionFile",'adb push "'.$File.'"'." ", 'a', 't');
$File = replace ("$File", "$g_LocalRoot", "$g_DeviceRoot", '0', , );
$File = replacelist ("$File", '/,\,\\,/\,\/', '/', ',' '0');
$File = regexreplace ("$File", '//', '/', '0');
writefile ("$g_ExecutionFile",'"'.$File.'"'."<crlf>", 'a', 't');
}
run ("$g_ExecutionFile", , '1', '1');
}