Script: Send files to Android device over USB

Discuss and share scripts and script files...
Post Reply
40k
Posts: 234
Joined: 09 Dec 2011 21:25

Script: Send files to Android device over USB

Post by 40k »

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:

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');
 }
 
 
 
 
 
 
 
 
 

I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

admin
Site Admin
Posts: 66294
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Script: Send files to Android device over USB

Post by admin »

Why do you unnecessarily quote variables ("$g_ConfigurationFile")? Is it the heat or the humidity? :P

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Script: Send files to Android device over USB

Post by serendipity »

Thanks for this script. I will test it out. The only time I use WE is to view files on my android device and this will help somewhat.
Maybe one day XY will support this.

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Script: Send files to Android device over USB

Post by 40k »

admin wrote:Why do you unnecessarily quote variables ("$g_ConfigurationFile")? Is it the heat or the humidity? :P
I can't figure out what coding convention I want to use for Xy so I sort of make my own. Not that I really stick to it though, ahem... :whistle:
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Script: Send files to Android device over USB

Post by 40k »

I'm working on this one at the moment. The next version should consist of just one script that sends any selected items, files and / or folder to your android device.
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Script: Send files to Android device over USB

Post by j_c_hallgren »

Just wondering...what advantages does this have over http://www.airdroid.com/ which I and others use all the time for this type function? I presume you're aware of AirDroid? If not, why not?
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Script: Send files to Android device over USB

Post by 40k »

j_c_hallgren wrote:Just wondering...what advantages does this have over http://www.airdroid.com/ which I and others use all the time for this type function? I presume you're aware of AirDroid? If not, why not?
This works when you need it to work. Air droid needs a WiFi connection.
Aside from that, you should not need to install 3rd party software to transfer your files. The security implications alone...

I was not aware of air droid, but again, things like file transfer are just too important to be dependent on often sketchy wireless connections in my book.
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

Post Reply